2

I am trying make a pyramid plot with R. The I found a example code in the internet that does what I want. The problem is that I am not working with small numbers as in the example. My plot has values of 3,000,000 to 12,000,000 but only 10 bars per side. Never the less it takes for ever create the plot with the larger numbers and output pdf file is about 800mb of size.

pyramid.plot(x,y,labels=groups,main="Performance",lxcol=mcol,rxcol=fcol,gap=0.5,show.values=TRUE)

Why is the performance so bad? Shouldn't get scaled automatically?

Update:

pdf(file='figure1.pdf')
library(plotrix)

x <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
y <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
groups <-c("g1","g2","g3","g4","g5","g6","g7","g8","g9","g11") 
pyramid.plot(x,y,labels=groups,main="Performance",gap=0.5,show.values=TRUE)
dev.off()

Both the export to pdf as well as the plotting screen takes multiple minutes.

mrks
  • 1,421
  • 2
  • 12
  • 20
  • 3
    Your example is not reproducible, so it will be difficult to answer. Please tell us the following: 1) In which package is `pyramid.plot`? 2) The results of `str(x)` and `str(y)` – Andrie Jul 14 '11 at 14:11
  • @Andrie, a quick search returned that `pyramid.plot` is in `plotrix` – Luciano Selzer Jul 14 '11 at 15:04
  • 3
    Creating an 800mb PDF sounds like an inches/pixels mixup when calling `pdf()` to save to disk. I'm guessing that's the part that's really slow, not the `pyramid.plot` call. But it's impossible to tell for sure from the question. – joran Jul 14 '11 at 16:07
  • 1
    I would like to up-arrow (up-vote) all the "not reproducible" comments more than once but I can't. Perfectly reasonable question, but not reproducible! – Ben Bolker Jul 14 '11 at 18:03
  • PS http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ben Bolker Jul 14 '11 at 20:13

1 Answers1

2

Internally, pyramid.plot is trying to do some stuff to finagle the axes accounting for the gap in the middle: if you do debug(pyramid.plot) and step through line-by-line you find where the problem is:

if (is.null(laxlab)) {
            laxlab <- seq(xlim[1] - gap, 0, by = -1)
            axis(1, at = -xlim[1]:-gap, labels = laxlab)
        }

in other words, pyramid.plot is trying to make an axis with ticks every 1 (!) unit. Something like this works OK:

pyramid.plot(x,y,labels=groups,
             main="Performance",gap=5e5,show.values=TRUE,
             laxlab=seq(0,1e7,by=1e6),raxlab=seq(0,1e7,by=1e6))

there are a few other vestiges of the fact that pyramid.plot was designed for demographic plots ... you might write to the package maintainer and ask him to think about generalizing the design of the axes a little bit ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453