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

Ali*_*vil 2 plot r ggplot2

distr用来形成以下分布:

library(distr)

G1 <- Gammad(shape=1.64, scale=0.766)
G2<- Gammad(shape=0.243, scale=4.414)
Run Code Online (Sandbox Code Playgroud)

现在为了比较这两个分布,我需要在一个窗口中绘制它们,但我不知道如何。我试过了,ggplot但显然它不适用于伽马函数。

mne*_*nel 5

使用 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')))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

使用基地

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

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

例如:

par(mfrow=c(2,3))
plot(G1, mfColRow=F)
plot(G2, mfColRow=F)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明