Plot Lognormal Probability Density in R

两盒软妹~` 提交于 2019-12-06 04:39:13

There is really nothing wrong in your code. You just forgot to:

  • use type = "l" in plot;
  • set a good ylim to hold all lines.

Here is a simple solution with matplot:

matplot(x, cbind(a,b,g), type = "l", ylab = "density", main = "log-normal",
        col = 1:3, lty = 1:3)

To add legend, use

legend("topright",
       legend = c("mu = 0, sd = 1", "mu = 0, sd = 1.5", "mu = 1.5, sd = 0.2"),
       col = 1:3,
       lty = 1:3)

You can also read ?plotmath for adding expressions. Try changing the legend argument above to:

legend = c(expression(ln(y) %~% N(0,1)),
           expression(ln(y) %~% N(0,1.5)),
           expression(ln(y) %~% N(1.5,0.2)))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!