Saturday, 31 August 2013

R (ggplot)- How to generate multiple plots (facets) based on data.frame with only one numeric variable and distinct categ. variables

R (ggplot)- How to generate multiple plots (facets) based on data.frame
with only one numeric variable and distinct categ. variables

starting with this kind of data:
colnames(mydata)<-c("digit","freq","bool")
1.1 1 false
1.1 2 false
1.1 20 true
1.1 3 false
1.1 7 false
1.2 8 false
1.2 25 false
1.2 10 false
1.2 60 true
1.2 28 false
1.3 7 false
1.3 0 false
1.3 56 true
1.3 12 false
1.3 7 false
1.3 4 false
1.4 3 false
1.4 87 false
1.4 25 false
1.4 56 false
1.4 167 true
2.1 46 false
2.1 25 false
2.1 75 true
2.1 20 false
2.1 12 false
2.1 15 false
... I would like to create muliple plots based on the digit field in the
data using ggplot2.
I tried
ggplot(mydata, aes(y = mydata$freq, x = seq(1, length(mydata$freq)))) +
geom_point() +
facet_wrap(~ mydata$digit)
But it won't work. Additionally, I would like to give two distinct colors
to the mydata$freq data according to the false or true $bool annotation.
So, basically something like geom_point(aes(colour=mydata$bool)) within
each subplot (facet).
How can I make it work?

No comments:

Post a Comment