0

I need to generate a figure looking something like this:

enter image description here

Basically I have 3 separate plots generated separately using ggplot, and I want to some how combine them in a single figure. The arrangement I want is exactly of that in the above figure. I have tried layout() but i dont think it works with ggplot, or maybe I am doing something wrong,

Also I want to put a label a, b, c on top left corner of the each plot.

Thanks in advance

nrussell
  • 18,382
  • 4
  • 47
  • 60
show_stopper
  • 288
  • 5
  • 17

1 Answers1

1

There are some good answers in @Henrik's link, but here's another solution using a user-defined function multiplot, which can be found on this webpage:

library(ggplot2)
##
p1 <- ggplot(
  data=mtcars,
  aes(x=wt))+
  geom_histogram(binwidth=.5)+
  ggtitle("(A) Histogram of wt")+
  ylab("Frequency")
##
p2 <- ggplot(
  data=mtcars,
  aes(x=mpg))+
  geom_histogram(binwidth=5)+
  ggtitle("(B) Histogram of mpg")+
  ylab("Frequency")
##
p3 <- ggplot(
  data=mtcars,
  aes(x=disp))+
  geom_histogram(binwidth=50)+
  ggtitle("(C) Histogram of disp")+
  ylab("Frequency")
##
> multiplot(p1,p2,p3,layout=matrix(c(1,2,1,3),nrow=2))

enter image description here

nrussell
  • 18,382
  • 4
  • 47
  • 60