I have a data set of the following form: Johnson 4 Smith 4 Smith 2 Smith 3 Garcia 1 Garcia 4 Rodriguez 2 Adams 2 Adams 3 Adams 4 Turner 4 Turner 3 And I'd like to create a stacked bar chart that has scores on the x-axis and the bars are broken up by judges name. Whenever I try to do this though (barplot(table(judges,scores)) it always creates more groups than actual judges. Would anyone know how to graph this and color code the names appropriately? -- View this message in context: http://r.789695.n4.nabble.com/Help-Creating-a-Stacked-Bar-Chart-with-Color-Coding-tp2305487p2305487.html Sent from the R help mailing list archive at Nabble.com.
It is a little complicate for me to transform the table. Hope it works for
you.
x <- read.table(textConnection("Johnson 4
Smith 4
Smith 2
Smith 3
Garcia 1
Garcia 4
Rodriguez 2
Adams 2
Adams 3
Adams 4
Turner 4
Turner 3 "),header=F)
## sort data
x<-x[order(x[,1],-x[,2]),]
## add another column to be the index used for reshape
x$times<-sequence(rle(as.character(x[,1]))$lengths)
y <- t(reshape(x, timevar="times", idvar="V1",
direction="wide"))
colnames(y)<-y[1,]
barplot(y[-1,],col=27:29)
-----
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Help-Creating-a-Stacked-Bar-Chart-with-Color-Coding-tp2305487p2306464.html
Sent from the R help mailing list archive at Nabble.com.