0

I was trying to plot boxplot with scales="free_y" but I found out that it is not possible in ggplot2.

So I used

library(gridExtra)
grid.arrange(boxplot1,boxplot2,boxplot3,ncol=3)

The results are very nice but is it possible to text the strips for individual plots, similarly as done using facet_grid()?

I would appreciate any thoughts and suggestions.

Here is the example:

data(mpg)
ggplot(mpg,aes(x=manufacturer,y=displ))+facet_grid(.~class)+geom_boxplot()

now the boxplot can not use scales="free_y" therefore I did something this

box1<-ggplot(subset(mpg,class=="2seater"),aes(x=manufacturer,y=displ))+geom_boxplot()
box2<-ggplot(subset(mpg,class=="minivan"),aes(x=manufacturer,y=displ))+geom_boxplot()
box3<-ggplot(subset(mpg,class=="suv"),aes(x=manufacturer,y=displ))+geom_boxplot()
grid.arrange(box1,box2,box3,ncol=3)

the results are nice with appropriate scales but I lose the strip text now on each plot.

Is it possible to get them on individually and then i can use

grid.arrange()

Thanks in advance.

badu_cool
  • 5
  • 1
  • 4
  • Can you please some reproducible example? eg. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – holzben Aug 27 '13 at 06:11

1 Answers1

1

If your plots are faceted only by one variable then you can use facet_wrap() instead of facet_grid(), so you will be able to use scales="free_y".

ggplot(mtcars,aes(as.factor(cyl),mpg))+geom_boxplot()+
          facet_wrap(~gear,scales="free_y") 

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201