【问题标题】:Plotting multiple curves of Weibull distribution in one graph在一张图中绘制多条 Weibull 分布曲线
【发布时间】:2021-05-05 02:40:43
【问题描述】:

我需要在一张图中绘制多条具有不同形状和比例参数的 Weibull 分布曲线。我可以使用以下代码绘制第一条曲线:

x=seq(1,15,0.1)
plot(dweibull(x, shape= 3.2, scale=5.6), type="l", col= "red")

现在,我想在同一个图中添加具有不同形状和比例参数的其他曲线(例如:形状 = 2.8 和比例 = 6.4)。任何帮助都非常感谢

【问题讨论】:

  • lines(dweibull(x, shape= 2.8, scale=6.4), type="l", col= "blue")

标签: r


【解决方案1】:

基于 tidyverse 的解决方案可能是:

d1 <- tibble(
        Shape=3.2, 
        Scale=5.6, 
        Colour="red", 
        X=seq(1, 15, 0.1), 
        Y=dweibull(X, Shape, Scale)
       )
d2 <- tibble(
        Shape=2.8, 
        Scale=6.4, 
        Colour="blue", 
        X=seq(1, 15, 0.1), 
        Y=dweibull(X, Shape, Scale)
      )

d <- d1 %>% bind_rows(d2)
d %>% ggplot() + geom_line(aes(x=X, y=Y, colour=Colour))

如果有帮助,绘制所有形状和比例组合的有效方法可能是:

d <- tibble() %>% 
       expand(
         Shape=c(3.2, 5.6),
         Scale=c(2.8, 6.4),
         X=seq(1, 15, 0.1)
       ) %>% 
       mutate(
         Y=dweibull(X, Shape, Scale)
       )
d %>% 
  ggplot() + 
    geom_line(aes(x=X, y=Y, linetype=as.factor(Shape), colour=as.factor(Scale)))

这将处理(几乎)任意数量的ScaleShape 组合,并且可以自定义绘图以改善其外观。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多