compare different datasets with stacked bar graphs in R -



compare different datasets with stacked bar graphs in R -

this question has reply here:

compare different datasets stacked bar graphs in r 2 answers

i need compare 2 different methods each of them has 3 different results in 1 graph using stacked bar style.

i want draw plot x axis shows experiment , y axis shows results. , each bar fills 3 results in stacked bar format.

experiment method resuult1 result2 result3 1 m1 1 2 3 1 m2 4 5 6 2 m1 7 8 9 2 m2 10 11 12 3 m1 13 14 15 3 m2 16 17 18

your data:

dataset <- data.frame( experiment = c(1,1,2,2,3,3), method = c("m1","m2","m1","m2","m1","m2"), result1 = seq(1,16,by=3), result2 = seq(2,17,by=3), result3 = seq(3,18,by=3))

we first need shift info different format:

foo <- t(as.matrix(dataset[,c("result1","result2","result3")])) bar <- cbind(foo[,1:2],na,foo[,3:4],na,foo[,5:6])

look @ bar understand what's happening here. next, plot , add together axis annotation:

baz <- barplot(height=bar,beside=false, legend.text=rownames(bar),args.legend=list(x="topleft",inset=0.05)) axis(1,at=baz[c(1,2,4,5,7,8)],labels=dataset[,"method"],tick=false) axis(1,at=c(mean(baz[1:2]),mean(baz[4:5]),mean(baz[7:8])), labels=paste("experiment",1:3),tick=false,line=2)

r

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -