我正在尝试在ggplot中复制该图
library(MASS)
data(galaxies)
truehist(galaxies,ymax=0.0002,col="green", main="base R: Triangular Under Smooth")
lines(density(galaxies,kernel="triangular",bw=500),col="red",main="Triangular_Under")
所以我尝试了:
ggplot() + aes(galaxies) +
geom_density() +
stat_density(kernel = "gaussian", bw = 500) +
labs(title = "ggplot: Triangular Under Smooth")
我想要的预期图应该没有暗密度图(只想显示密度线),就像在基础图中一样。
答案 0 :(得分:1)
尝试一下
ggplot() +
aes(galaxies) +
geom_histogram(aes(y=..density..), bins = 15) +
stat_density(kernel = "gaussian", bw = 500, fill = NA, col = "red") +
labs(title = "ggplot: Triangular Under Smooth")