By using optional arguments (...) in a function as shown in the new population pyramid graph

Wanting to show the distribution of survey participants by level, I went to a recently released package pyramid

and tried it. Since the font on the x-axis is too large and there seems to be no other formatting options to fix this, I realized I didn't know how to add the "other options" allowed ... in the pyramid call.

install.packages("pyramid")
library(pyramid)
level.pyr <- data.frame(left = c(1, 4, 6, 4, 41, 17),
                        right = c(1, 4, 6, 4, 41, 17),
                        level = c("Mgr", "Sr. Mgr.", "Dir.", "Sr. Dir.", "VP", "SVP+"))
pyramid(level.pyr, Laxis = seq(2,50,6), Cstep = 1, Cgap = .5, Llab = "", Rlab = "", Clab = "Title", GL = T, Lcol = "deepskyblue", Rcol = "deepskyblue", Ldens = -1, main = "Distribution of Participants in Survey")

      

Agreed, the plot below looks odd because the left and right sides are the same, not men and women. But my question is how to call options and make something like "Laxis.size = 2" from "Raxis.font =" bold ".

enter image description here

Alternatives to this new pyramid plotting package include plot, grid and base R as shown here: Population density density in r By the way, if there was a ggplot method, I'd like to try it.

+3


source to share


1 answer


Unlike Roland, and now nrussell guesses (without looking at the code explicitly), expressed in the comments, the point arguments will not be passed to the plotting procedure pyramid

, despite the fact that this is a basic graphing function. Arguments aren't even passed on to the call axis

, although that would seem reasonable. The tick mark along the x-axis is plotted with a call text()

. You can hack text calls to accept a named argument of your choice and it will be passed through the dot mechanism. You seem to be open to other options, and I would recommend using plotrix::pyramid.plot

, as Jim Lemon does a better job of documenting his routines, and most likely they will use R's standard construction conventions:

library(plotrix)
pyramid.plot(lx,rx,labels=NA,top.labels=c("Male","Age","Female"),
  main="",laxlab=NULL,raxlab=NULL,unit="%",lxcol,rxcol,gap=1,space=0.2,
  ppmar=c(4,2,4,2),labelcex=1,add=FALSE,xlim,show.values=FALSE,ndig=1,
  do.first=NULL)


with( level.pyr, pyramid.plot(lx=left, rx=right, labels=level, 
        gap =5, top.labels=c("", "Title", ""), labelcex=0.6))

      



enter image description here

+3


source







All Articles