Dejian Zhao
unread,Jun 4, 2014, 12:58:48 PM6/4/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
I ran a program and got a count summary. Now I want to generate a figure
like the one produced with the following command:
ggplot(mtcars,aes(factor(cyl))) + geom_bar(aes(fill=factor(vs)),
position="fill")
The only difference between my own data and the above example is that I
got the count summary from another program. It is mentioned in Hadley's
book "ggplot2: Elegant Graphics for Data Analysis" how to display
precomputed statistics, but there is no example in the book. The
description of the section is as below:
"4.9.2 Displaying precomputed statistics
If you have data which has already been summarised, and you just want to
use it, you’ll need to use stat_identity(), which leaves the data
unchanged, and then map the appropriate variables to the appropriate
aesthetics."
I tried without success. Does anyone know how to draw the figure?
My dataset is like this:
>df <- data.frame(sample=c(rep("case1",3), rep("case2",3),
rep("case3",3)), group=rep(letters[1:3],3), countSum=11:19)
> df
sample group countSum
1 case1 a 11
2 case1 b 12
3 case1 c 13
4 case2 a 14
5 case2 b 15
6 case2 c 16
7 case3 a 17
8 case3 b 18
9 case3 c 19
The figure I want is like the one produced with the above-mentioned
first command, with "sample" corresponding to "factor(cyl)", "group" to
"factor(vs)", and "countSum" to "count".
Thanks!
Dejian