我可以将平均值设置为2位小数吗?
fun_mean <- function(x){return(data.frame(y=mean(x),label=mean(x,na.rm=T)))}
goo = ggplot(dataset1, aes(x=Pleace, y=Scored.Probabilities)) +
geom_boxplot(aes(fill=Pleace)) +
stat_summary(fun.y = mean, geom="point",colour="darkred", size=3) +
stat_summary(fun.data = fun_mean, geom="text", vjust=-0.7)
print (goo)
答案 0 :(得分:4)
使用round(x, digits = 2)
fun_mean <- function(x){return(round(data.frame(y=mean(x),label=mean(x,na.rm=T)),digit=2))}
goo <- ggplot(dataset1, aes(x=Pleace, y=Scored.Probabilities)) +
geom_boxplot(aes(fill=Pleace)) +
stat_summary(fun.y = mean, geom="point",colour="darkred", size=3) +
stat_summary(fun.data = fun_mean, geom="text", vjust=-0.7)
goo
参考:https://stat.ethz.ch/R-manual/R-devel/library/base/html/Round.html