【发布时间】:2021-07-01 12:27:36
【问题描述】:
我有一堆数据,我已经拟合了伽马分布。我的直方图和拟合曲线很好,但现在我想绘制一个直方图和带有 x 的对数刻度曲线。使用 scale_x_log10 对直方图效果很好,但我不能让它对 stat_function/geom_line 起作用。
我知道这是因为 stat_function 现在采用日志值,但我不确定如何事先转换 gamma 函数以使其正常工作。以下是相关图片和代码sn-ps:
这是原图:
fit.gamma2 <- fitdist(myvalues[,1],distr="gamma",method="mme")
ggplot(myvalues, aes(x = V1)) +
geom_histogram(aes(y =..density..),
boundary = 0,
binwidth = sirina,
col="black",
fill="blue",
alpha=.2) +
stat_function(fun=dgamma,
args=list(shape = fit.gamma2$estimate["shape"],
rate = fit.gamma2$estimate["rate"])) +
labs(title="Histogram žarkov + Gama porazdelitev (MM)",
x = "Medprihodni časi (s)",
y = "Gostota")
这是使用 scale_x_log10 后的同一张图。红色曲线应该是拟合曲线,但明显偏离了。
ggplot(myvalues, aes(x = V1)) +
geom_histogram(aes(y =..density..),
boundary = 0,
binwidth = sirina_log,
col="black",
fill="blue",
alpha=.2) +
stat_function(fun=dgamma,
args=list(shape = fit.gamma2$estimate["shape"],
rate = fit.gamma2$estimate["rate"])) +
# geom_line(aes(x=V1,y=dgamma(V1,fit.gamma2$estimate["shape"], fit.gamma2$estimate["rate"])), color="red", size = 1) +
scale_x_log10()
我已尝试应用 10**x 形式的值,但由于我的原始数据范围在 0.1 和 800 之间,一些值然后转义为 Inf。
【问题讨论】: