0

I'm trying to plot density plots for the asymmetric Laplace distribution onto one single plot.

I have defined the two densities, one for the asymmetry parameter = 0.5 and another for the parameter = 0.25.

My plot statement plots one graph correctly.

I would like to put both onto the same graph, and maybe a third one as well?

library(ald)
sseq = seq(-8,8,0.01)
dens = dALD(y=sseq,mu=0,sigma=1,p=0.25)
dens2= dALD(y=sseq,mu=0,sigma=1,p=0.5)
plot(sseq,dens,type="l",lwd=2,col="red",xlab="u",ylab=parse(text="f[p](u)"), main="ALD Density function")

legend("topright", legend=c("ALD for p=0.5"),lty=c(1),
       lwd=c(1),col=c("red"),title="Values for different quantiles:")
xndr_h
  • 13
  • 3
  • 1
    Possible duplicate of [How to overlay density plots in R?](https://stackoverflow.com/questions/6939136/how-to-overlay-density-plots-in-r) – mischva11 Apr 26 '19 at 10:24
  • I should've probably asked before I posted my answer, but is there a reason not to use `ggplot2` ? – DS_UNI Apr 26 '19 at 10:46

1 Answers1

1

You can do that easily with ggplot2:

library(ggplot2)
ggplot(data.frame(sseq, dens, dens2)) + 
  geom_line(aes(sseq, dens, color = 'ALD for p=0.5')) + 
  geom_line(aes(sseq, dens2, color = 'ALD for p=0.25')) +
  labs(x="u",y=parse(text="f[p](u)"),
      title="ALD Density function") +
  scale_color_discrete(name="Values for different quantiles:") +
  theme_minimal()

enter image description here

DS_UNI
  • 2,600
  • 2
  • 11
  • 22