【问题标题】:Avoid curve be trimmed in the plot in R避免曲线在 R 的图中被修剪
【发布时间】:2021-01-21 15:38:58
【问题描述】:

如何避免我的曲线(绿线)被切断?

x <- Phoenix_August_clean$Sum.Precipitation.Total.August
curve(dnorm(x, mean = fit.gaussian2$estimate[1], sd = fit.gaussian2$estimate[2]), lwd=3, col="red", add=TRUE)
curve(dgamma(x, fit.gamma.mme$estimate[1], fit.gamma.mle$estimate[2]), col="orange", lwd=3, add=TRUE) #Maximum likelihood
curve(dgamma(x, fit.gamma.mme$estimate[1], fit.gamma.mme$estimate[2]), col="green", lwd=3, add=TRUE) #Method of moments
legend("topright",legend=c("Normal","Gamma - ML","Gamma - MM"), col=c("red","orange","green"), lty=1, lwd=1)

结果:

【问题讨论】:

  • 绘图会根据第一个绘图函数中显示的数据自动设置ylim(据称是hist的某种形式),但它是在您添加超出限制的线之前设置的.手动设置ylim=

标签: r plot histogram probability


【解决方案1】:

限制是根据当时已知的数据在第一个图上设置的(显然是为您调用 hist),因此您需要自己在 that 上设置 ylim=调用,基于您打算绘制的曲线。

问题图:

hist(mtcars$disp, freq=FALSE)
curve(dgamma(x-100, 50)/10, lwd=3, col="red", to=500, add=TRUE)

固定情节,手动添加ylim=...

hist(mtcars$disp, freq=F, ylim=c(0, 0.0055))
curve(dgamma(x-100, 50)/10, lwd=3, col="red", to=500, add=TRUE)

【讨论】:

    猜你喜欢
    • 2015-12-09
    • 1970-01-01
    • 2011-05-21
    • 2022-01-25
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多