使用ggplot2运行这段代码时,geom_freqpoly没有打印

使用ggplot2运行这段代码时,geom_freqpoly没有打印,r,ggplot2,plot,R,Ggplot2,Plot,我不知道为什么geom_freqpoly没有作图。当我运行块时,我只看到直方图,而看不到折线图 library(ggplot2) lambda1 = 1/2 sequence = seq(1, 10000, by=1) df1 = tibble(x=seq(1, 10000, by=1), expo1 = lambda1*exp(-(lambda1)*x)) lambda2 = 1/5 df2 = tibble(x=seq(1, 10000, by=1), expo2 = lam

我不知道为什么geom_freqpoly没有作图。当我运行块时,我只看到直方图,而看不到折线图

library(ggplot2)
lambda1 = 1/2
sequence = seq(1, 10000, by=1)
    

df1 = tibble(x=seq(1, 10000, by=1), expo1 = lambda1*exp(-(lambda1)*x))

lambda2 = 1/5

df2 = tibble(x=seq(1, 10000, by=1), expo2 = lambda2*exp(-(lambda2)*x))


ggplot() +
  geom_histogram(aes(x=expo2, y=..density..), binwidth=.5, colour="blue", fill="white") +
  geom_histogram(aes(x=expo1, y=..density..), binwidth=.5, colour="red", fill="white") +
  geom_freqpoly(data=df2, aes(x=expo2, y=..density..), binwidth=.5, colour="blue") + 
  geom_vline(aes(xintercept=mean(expo2)), color="blue", linetype="dashed", size=1) +
  geom_density(alpha=.2, fill="#FF6666") +
  geom_freqpoly(data=df1, aes(x=expo1, y=..density..), binwidth=.5, colour="red") + 
  geom_vline(aes(xintercept=mean(expo1)), color="red", linetype="dashed", size=1) +
  geom_density(alpha=.2, fill="#FF6666") +
  xlim(0,10) +
  ylim(0,0.5)+
  ggtitle("Distribution of averages of random exponential distribution with their means", "theta = 2 in red and theta = 5 in ")+
  xlab("Averages of the distribution")+
  ylab("Density")

在许多几何图形行中缺少
数据
对象。每个geom都需要数据。你想干什么?在一个图上绘制两个数据帧?你的天平到处都是。试试这个


图书馆(GG2)
图书馆(tibble)

是的,我试图在一个图中绘制两个数据帧。即使在指定了数据对象之后,线图仍然没有打印。几何密度也需要美观。我现在正在摆弄它。刻度需要是x=0到10,当df1=tibble(x=seq(1,10000,by=1),expo1=rexp(10000,lambda1))和df2=tibble(x=seq(1,10000,by=1),expo2=rexp(10000,lambda2))时,它看起来很好。我试着用实际的PDF复制它,用lambda*exp(-(lambda)*x)表示指数分布。df1和df2已经是密度函数了。做直方图、频率图或密度图是没有意义的。你已经有了指数1和指数2的密度,这就是你想要的吗?