On 02/19/2011 06:46 AM, Li, Qinghong, ST. LOUIS, NRC St. Louis Petcare
wrote:
Sorry the data were all messed up. Let me try again.
Can anyone help me to plot a chart graph? I have a data set like this. I
would like a bar chart graph which mouse1's two treatments are clustered
together, so on.
I tried with barplot, but couldn't get it right.
Mouse1 Mouse2 Mouse3
Trial C T C T C T
1 2.4 4.3 2 4.3 2 7
2 2.8 5.4 2.8 6 2 8
3 3.1 4.5 3 4.5 3 7
4 3.1 4.4 3.1 4 3.1 7
5 2 4.1 2 4.1 2 7
6 2.2 4 2.2 3 4 6.9
7 2.7 5 4 5 2.7 6.5
8 4.5 5.6 4.5 6 4 5.6
9 2.3 4.5 2.3 4.5 2.3 4
10 3 4 4 6 2 4
-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Li,Qinghong,ST. LOUIS,NRC St. Louis Petcare
Sent: Friday, February 18, 2011 12:06 PM
To: r-help@r-project.org
Subject: [R] clustered bar chart help
Hi,
Can anyone help me to plot a chart graph? I have a data set like this. I
would like a bar chart graph which mouse1's two treatments are clustered
together, so on.
I tried with barplot, but couldn't get it right.
Hi Johnny,
Try this (assume your data frame is named "mp"):
# string the scores out in a vector
mpv<-as.vector(as.matrix(mp))
# make another two vectors specifying which score
# belongs to which mouse and which condition
# and combine these into a data frame
mp2<-data.frame(mpv,mouse=rep(c("M1","M2","M3"),each=20),
cond=rep(c("C","T","C","T","C","T"),each=10))
library(plotrix)
# make a list of colors for the bars
mc_colors<-list("lightgray",2:4,c("orange","brown"))
# display a clustered bar chart
barNest(mpv~mouse+cond,mp2,col=mc_colors,main="Mouse performance")
Jim
______________________________________________
R-help@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.