但是,直方图在x轴上的长度为13,而gamma分布在x轴上的长度为512,但人们一直抱怨`
错误:美学必须为长度1或与数据相同 (13):x,y
den <- density(x) # x's length is 13, however den's length is 512
dat <- data.frame(x = den$x, y = den$y)
dataframe = data.frame(days = days, x = x)
ggplot(data = dat) +
geom_line(aes(x=dat$x, y=dgamma(dat$x,shape, rate)), color="red", size = 1) +
theme_classic()
bplot = ggplot(data = dataframe,aes(x = dataframe$days, y = (dataframe$x)/sum(dataframe$x)));
bplot +
geom_bar(stat="identity", width=0.5)+
geom_line(aes(x=dat$x, y=dgamma(dat$x,shape, rate)), color="blue", size = 1)
答案 0 :(得分:2)
您必须在data
调用中将dat
参数设置为geom_line
,这样才能将美观性映射到新的dat
而不是dataframe
:
bplot +
geom_bar(stat="identity", width=0.5)+
geom_line(data = dat, aes(x=dat$x, y=dgamma(dat$x,shape, rate)), color="blue", size = 1)