Alison Macalady
2010-Aug-23 18:02 UTC
[R] change order of plot panels in faceted ggplot/qplot
Hi, I have a 5-paneled figure that i made using the facet function in qplot (ggplot). I've managed to arrange the panels into two rows/ three columns, but for the sake of easy visual comparisons between panels in my particular dataset, I want to have the two plots on the bottom align on the right hand side of the figure instead of the left. Here's an example: m <- matrix(rnorm(300), nrow = 60) colnames(m) <- paste('V', 1:5, sep = '') b <- data.frame(site = factor(rep(c('A', 'B', 'C', 'D', 'E'), each = 12)), status = factor(rep(rep(c('D','L'), each = 3), 10)), as.data.frame(m)) qplot(V2, V1, data=b, shape=status) + scale_shape_manual(value=c(1,16)) +facet_wrap(~site,nrow=2) What I would like to do is keep the 2 row shape, keep the order (A,B,C) of the top plots, but have the D and E panels in this example align under the B and C plots. Is this possible using qplot? Many thanks, Ali
This is easy to do in xyplot (latice package) via the index.cond and skip arguments. Don't know about ggplot though. -- Bert On Mon, Aug 23, 2010 at 11:02 AM, Alison Macalady <ali at kmhome.org> wrote:> Hi, > > I have a 5-paneled figure that i made using the facet function in qplot > (ggplot). ?I've managed to arrange the panels into two rows/three columns, > but for the sake of easy visual comparisons between panels in my particular > dataset, I want to have the two plots on the bottom align on the right hand > side of the figure instead of the left. > > Here's an example: > m <- matrix(rnorm(300), nrow = 60) > colnames(m) <- paste('V', 1:5, sep = '') > b <- data.frame(site = factor(rep(c('A', 'B', 'C', 'D', 'E'), each = 12)), > status = factor(rep(rep(c('D','L'), each = 3), 10)), as.data.frame(m)) > > qplot(V2, V1, data=b, shape=status) + > scale_shape_manual(value=c(1,16))+facet_wrap(~site,nrow=2) > > What I would like to do is keep the 2 row shape, keep the order (A,B,C) of > the top plots, but have the D and E panels in this example align under the B > and C plots. > > Is this possible using qplot? > > Many thanks, > Ali > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Hadley Wickham
2010-Aug-24 20:26 UTC
[R] change order of plot panels in faceted ggplot/qplot
On Mon, Aug 23, 2010 at 1:02 PM, Alison Macalady <ali at kmhome.org> wrote:> Hi, > > I have a 5-paneled figure that i made using the facet function in qplot > (ggplot). ?I've managed to arrange the panels into two rows/three columns, > but for the sake of easy visual comparisons between panels in my particular > dataset, I want to have the two plots on the bottom align on the right hand > side of the figure instead of the left. > > Here's an example: > m <- matrix(rnorm(300), nrow = 60) > colnames(m) <- paste('V', 1:5, sep = '') > b <- data.frame(site = factor(rep(c('A', 'B', 'C', 'D', 'E'), each = 12)), > status = factor(rep(rep(c('D','L'), each = 3), 10)), as.data.frame(m)) > > qplot(V2, V1, data=b, shape=status) + > scale_shape_manual(value=c(1,16))+facet_wrap(~site,nrow=2) > > What I would like to do is keep the 2 row shape, keep the order (A,B,C) of > the top plots, but have the D and E panels in this example align under the B > and C plots. > > Is this possible using qplot?Not currently. Regards, Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/