I am trying to generate a plot for Lognormal Probability Density in R, with 3 different means log and standards deviation log. I have tried the following, but my graph is so ugly and does not look good at all.
x<- seq(0,10,length = 100)
a <- dlnorm(x, meanlog = 0, sdlog = 1, log = FALSE)
b <- dlnorm(x, meanlog = 0, sdlog = 1.5, log = FALSE)
g <- dlnorm(x, meanlog = 1.5, sdlog = 0.2, log = FALSE)
plot(x,a, lty=5, col="blue", lwd=3)
lines(x,b, lty=2, col = "red")
lines(x,g, lty=4, col = "green")
I even was trying to add legend on the right top for each mean log and standard deviation log, but it would not work with me. I was wondering if someone could guide me out with that.
There is really nothing wrong in your code. You just forgot to:
type = "l"
inplot
;ylim
to hold all lines.Here is a simple solution with
matplot
:To add legend, use
You can also read
?plotmath
for adding expressions. Try changing thelegend
argument above to: