gpt4 book ai didi

R-boxplot 设置为 2 个小数位

转载 作者:行者123 更新时间:2023-12-04 12:20:03 25 4
gpt4 key购买 nike

我可以将平均值设置为小数点后两位吗?

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)

最佳答案

使用 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

enter image description here

关于R-boxplot 设置为 2 个小数位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29838224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com