r - ggplot2 : Plot mean with geom_bar -


i have following data frame:

test2 <- data.frame(groups = c(rep("group1",4), rep("group2",4)),      x2 = c(rnorm(4), rnorm(4)) ,      label = c(rep(1,2),rep(2,2),rep(1,2),rep(2,2))) 

and plotting bar graphs each label per group using:

ggplot(test2, aes(label, x2, fill=as.factor(groups))) +      geom_bar(position="dodge", stat="identity") 

enter image description here

however, cannot seem able find stat="mean" can plot means on each bar graph instead of identity.

thanks help.

simply use stat = "summary" , fun.y = "mean"

ggplot(test2) +    geom_bar(aes(label, x2, fill = as.factor(groups)),             position = "dodge", stat = "summary", fun.y = "mean") 

enter image description here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -