我有一个介于 0 和 1 之间的数据集,其中包含大约 20% 的 0。我注意到 stat_summary
从 ggplot
计算的平均值与手工计算的不同。为什么?
set.seed(190)
b<-runif(1000)*1e-6
#Create 0s
b[sample(NROW(b),200)]<-0
#Plot it and create a x for the mean.
tibble(value=b, name=rep(1,1e3)) %>%
ggplot(aes(x=name,y=b))+
geom_boxplot()+
scale_y_log10()+
stat_summary(fun=mean, geom="point", shape=4, size=3, color="black") ->a
ggplotly(a)
tibble(value=b, name=rep(1,1e3)) %>%
summarise(mean(b))
4.068419e-07