ggplot2 : Plot mean with geom_bar

后端 未结 3 1559
你的背包
你的背包 2020-11-30 03:33

I have the following data frame:

test2 <- data.frame(groups = c(rep(\"group1\",4), rep(\"group2\",4)), 
    X2 = c(rnorm(4), rnorm(4)) , 
    label = c(re         


        
3条回答
  •  攒了一身酷
    2020-11-30 03:54

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

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

提交回复
热议问题