ggplot stat_summary 的平均值与计算平均值不同

时间:2021-03-26 11:55:06

标签: r

我有一个介于 0 和 1 之间的数据集,其中包含大约 20% 的 0。我注意到 stat_summaryggplot 计算的平均值与手工计算的不同。为什么?

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)

enter image description here 手动计算这个平均值:

tibble(value=b, name=rep(1,1e3))  %>% 
  summarise(mean(b))

4.068419e-07    

0 个答案:

没有答案
相关问题