I have yet another question about ggplot2... but this time I am not even sure what I want to do would be possible... Let's start with a simple example; this is what I have so far:
library(reshape2)
library(ggplot2)
a.df <- data.frame(
id=c('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'),
var1=c(25,35,46,19,35,68,78,23,65,78,98,32,65,74,24,56,78,12,34,76,87,12,54,87,34),
group1=c(1,2,'NONE','NONE',1,2,2,1,3,4,3,'NONE','NONE',4,4,3,1,1,2,3,4,'NONE','NONE',2,3),
group2=c(1,'NONE',1,1,2,2,'NONE',2,'NONE',2,3,4,3,4,1,'NONE',1,3,4,'NONE',4,4,3,'NONE',2)
)
ggplot(data=subset(a.df,group1!='NONE'), aes(x=var1)) +
geom_density() +
facet_grid(. ~ group1)
ggplot(data=subset(a.df,group1=='NONE'), aes(x=var1)) +
geom_density()
ggplot(data=subset(a.df,group2!='NONE'), aes(x=var1)) +
geom_density() +
facet_grid(. ~ group2)
ggplot(data=subset(a.df,group2=='NONE'), aes(x=var1)) +
geom_density()
So what I would like to do here are the following:
1-First, just divide the facets in 2x2, instead of 4x1 (I have tried with ncol=2, but did not work)
2-Plot the 2nd plot (subset(a.df,group1=='NONE')) along with each of the 4 facets of the 1st plot. Do the same for 3rd and 4th.
3-If possible, what would be great would be to have the 2 resulting plots (1st+2nd in 4 facets, and 3rd+4th in 4 facets as well) in one, but the problem I see here is that the facets depend on 2 grouping variables... would it be possible??
So all in all, I feel the input data.frame needs some remodeling, but I have no idea how to... Many thanks!!