【问题标题】:How to plot multiple densities on one plot?如何在一张图上绘制多个密度?
【发布时间】:2019-09-15 20:15:09
【问题描述】:

我正在尝试将不对称拉普拉斯分布的密度图绘制到一个图上。

我已经定义了两种密度,一种用于不对称参数 = 0.5,另一种用于参数 = 0.25。

我的绘图语句正确绘制了一张图。

我想将两者放在同一张图上,也许还可以放第三张?

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:")

【问题讨论】:

标签: r plot


【解决方案1】:

您可以使用 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()

【讨论】:

    猜你喜欢
    • 2020-12-13
    • 1970-01-01
    • 2017-09-13
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2017-04-04
    相关资源
    最近更新 更多