Guest User

Untitled

a guest
May 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. plot_grid(p1, p2, p3, p4, align='vh', vjust=1, scale = 1)
  2.  
  3. library(ggplot2)
  4. library(cowplot)
  5. library(grid)
  6. library(gridExtra)
  7.  
  8. ToothGrowth$dose <- as.factor(ToothGrowth$dose)
  9.  
  10. #make 4 plots
  11.  
  12. p1<-ggplot(ToothGrowth, aes(x=dose, y=len)) +
  13. geom_boxplot()
  14.  
  15.  
  16. p2<-ggplot(ToothGrowth, aes(x=dose, y=supp)) +
  17. geom_boxplot()
  18.  
  19. p3<-ggplot(ToothGrowth, aes(x=supp, y=len)) +
  20. geom_boxplot()
  21.  
  22. p4<-ggplot(ToothGrowth, aes(x=supp, y=dose)) +
  23. geom_boxplot()
  24.  
  25. #combine using cowplot
  26.  
  27. plot<-plot_grid(p1, p2, p3, p4, align='vh', vjust=1, scale = 1)
  28.  
  29. #create common x and y labels
  30.  
  31. y.grob <- textGrob("Common Y",
  32. gp=gpar(fontface="bold", col="blue", fontsize=15), rot=90)
  33.  
  34. x.grob <- textGrob("Common X",
  35. gp=gpar(fontface="bold", col="blue", fontsize=15))
  36.  
  37. #add to plot
  38.  
  39. grid.arrange(arrangeGrob(plot, left = y.grob, bottom = x.grob))
Add Comment
Please, Sign In to add comment