首页 > 解决方案 > 如何将点添加到 freqpoly 图?

问题描述

我用 geom_freqpoly 绘制频率图:

ggplot(all,aes(x=time,color=type))
+geom_freqpoly(size=1.3,binwidth=2160) 
+theme_bw()+scale_x_datetime(breaks = date_breaks("2 hours"), labels=date_format("%H:%M"))

在此处输入图像描述

我想在情节中添加点,例如: 在此处输入图像描述

这个怎么做?非常感谢。

标签: r

解决方案


我有同样的问题,并发现我们可以告诉 geom_point() 使用与 geom_freqpoly() 相同的 bin 和计数,如下所示:

set.seed(8675309)
df <- data.frame(x=rnorm(100))

ggplot(data=df, aes(x=x)) +
  geom_freqpoly(binwidth=0.25) +
  geom_point(stat="bin", aes(y=..count..), binwidth=0.25)

我希望这有帮助!


推荐阅读