gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:32:18 24 4
gpt4 key购买 nike

我正在使用 distr 来形成以下分布:

library(distr)

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

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

最佳答案

使用 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

关于r - distr package-如何在一个窗口中绘制两个图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com