【发布时间】:2026-01-02 13:10:02
【问题描述】:
真实数据 = https://www.dropbox.com/s/pc5tp2lfhafgaiy/realdata.txt
模拟 = https://www.dropbox.com/s/5ep95808xg7bon3/simulation.txt
使用带宽 = 1.5 的此数据的密度图给出了以下图:
prealdata = scan("realdata.txt")
simulation = scan("simulation.txt")
plot(density(log10(realdata), bw=1.5))
lines(density(log10(simulation), bw=1.5), lty=2)
但是使用 ggplot2 绘制相同的数据,带宽参数(调整)似乎工作不同。为什么?
vec1 = data.frame(x=log10(realdata))
vec2 = data.frame(x=log10(simulation))
require(ggplot2)
ggplot() +
geom_density(aes(x=x, linetype="real data"), data=vec1, adjust=1.5) +
geom_density(aes(x=x, linetype="simulation"), data=vec2, adjust=1.5) +
scale_linetype_manual(name="data", values=c("real data"="solid", "simulation"="dashed"))
也非常欢迎就如何更好地平滑这些数据提出建议!
【问题讨论】: