将 ggplot2 中的两条密度曲线分开 stat_density
Separate stat_density for two density curves in ggplot2
我正在尝试生成一个 ggplot,它显示数据的直方图以及两条密度曲线,其中一条没有调整值,另一条有。
我尝试了以下代码:
ggplot(df, aes_string(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3)+
stat_density(bw="SJ", alpha=0)+
geom_density(colour="blue", fill="blue", alpha=.3)+
stat_density(bw="SJ", adjust=5, alpha=0)+
theme_bw()
但这会生成两条曲线重叠 100% 的图表...
使用的 .txt 数据框是 on my google drive
提前致谢!
向 geom_density
添加特定的 adjust
参数是否没有达到您想要的效果?
ggplot(df, aes(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3, adjust = 1)+
geom_density(colour="blue", fill="blue", alpha=.3, adjust = 2)+
theme_bw()
我正在尝试生成一个 ggplot,它显示数据的直方图以及两条密度曲线,其中一条没有调整值,另一条有。 我尝试了以下代码:
ggplot(df, aes_string(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3)+
stat_density(bw="SJ", alpha=0)+
geom_density(colour="blue", fill="blue", alpha=.3)+
stat_density(bw="SJ", adjust=5, alpha=0)+
theme_bw()
但这会生成两条曲线重叠 100% 的图表...
使用的 .txt 数据框是 on my google drive 提前致谢!
向 geom_density
添加特定的 adjust
参数是否没有达到您想要的效果?
ggplot(df, aes(x=value))+
geom_histogram(aes(y=..density..), colour="grey", fill="grey", alpha=.3)+
geom_density(colour="red", fill="red", alpha=.3, adjust = 1)+
geom_density(colour="blue", fill="blue", alpha=.3, adjust = 2)+
theme_bw()