0

I have found that the beanplot is the best way to represent my data. I want to look at multiple beanplots together to visualize my data. Each of my plots contains 3 variables, so each one looks something like what would be generated by this code:

library(beanplot)
a <- rnorm(100)
b <- rnorm(100)
c <- rnorm(100)
beanplot(a, b ,c ,ylim = c(-4, 4), main = "Beanplot", 
         col = c("#CAB2D6", "#33A02C", "#B2DF8A"), border = "#CAB2D6")

(Would have just included an image but my reputation score is not high enough, sorry)

I have 421 of these that I want to put into one long PDF (EDIT: One plot per page is fine, this was just poor wording on my part). The approach I have taken was to first generate the beanplots in a for loop and store them in a list at each iteration. Then I will use the multiplot function (from the R Cookbook page on multiplot) to display all of my plots on one long column so I can begin my analysis.

The problem is that the beanplot function does not appear to be set up to assign plot objects as a variable. Example:

library(beanplot)
a <- rnorm(100)
b <- rnorm(100)
plot1 <- beanplot(a, b, ylim = c(-5,5), main = "Beanplot", 
                  col = c("#CAB2D6", "#33A02C", "#B2DF8A"), border = "#CAB2D6")
plot1

If you then type plot1 into the R console, you will get back two of the plot parameters but not the plot itself. This means that when I store the plots in the list, I am unable to graph them with multiplot. It will simply return the plot parameters and a blank plot.

This behavior does not seem to be the case with qplot for example which will return a plot when you recall the stored plot. Example:

library(ggplot2)
a <- rnorm(100)
b <- rnorm(100)
plot2 <- qplot(a,b)
plot2

There is no equivalent to the beanplot that I know of in ggplot. Is there some sort of workaround I can use for this issue?

Thank you.

syntonicC
  • 371
  • 3
  • 17

1 Answers1

1

You can simply open a PDF device with pdf() and keep the default parameter onefile=TRUE. Then call all your beanplot()s, one after the other. They will all be in one PDF document, each one on a separate page. See here.

Community
  • 1
  • 1
Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48
  • I was so focused on trying to get the plots into a list it never occurred to me to look at the help file for `pdf()`. This worked perfectly. Thank you. – syntonicC Mar 27 '14 at 16:07