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:")
2
  • 1
    Possible duplicate of How to overlay density plots in R? Commented Apr 26, 2019 at 10:24
  • I should've probably asked before I posted my answer, but is there a reason not to use ggplot2 ? Commented Apr 26, 2019 at 10:46

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.