首页 文章

distr包 - 如何在一个窗口中绘制两个图?

提问于
浏览
2

我使用 distr 来形成以下发行版:

library(distr)

G1 <- Gammad(shape=1.64, scale=0.766)
G2<- Gammad(shape=0.243, scale=4.414)

现在为了比较这两个发行版我需要在一个窗口中绘制它们,但我不知道如何 . 我试过 ggplot 但显然它不能用于伽玛功能 .

1 回答

  • 4

    使用ggplot

    你可以用 stat_function

    例如

    # data that defines the range of x values you are interested in
    DF <-data.frame(x = c(1,8))
    ggplot(DF, aes(x=x)) + 
      stat_function(fun = d(G1), aes(colour = 'G1')) + 
      stat_function(fun = d(G2), aes(colour = 'G2')) + 
      scale_colour_manual('Distribution', 
               values = setNames(c('red', 'blue'), c('G1', 'G2')))
    

    enter image description here

    使用基础

    distr::plot 的帮助文件显示了如何组合绘图 .

    您需要自己设置 mfrow (或 mfcol ),然后在绘图调用中设置 mfColRow =FALSE .

    例如:

    par(mfrow=c(2,3))
    plot(G1, mfColRow=F)
    plot(G2, mfColRow=F)
    

    enter image description here

相关问题