2012-08-31 143 views
2

我使用distr,形成如下分布:distr包 - 如何在一个窗口中绘制两个图?

library(distr) 

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

,以这两个分布,我需要他们绘制在一个窗口比较,但我不知道怎么办。我试过ggplot,但显然它不适用于伽玛函数。

回答

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

+0

你好我想执行你的代码,但显然DF尚未确定,也某物缺失。 – AliCivil

+0

对不起。忘了复制这些行。 – mnel

相关问题