distr包 - 如何在一个窗口中绘制两个图? [英] distr package-how to draw two plots in one window?

查看:97
本文介绍了distr包 - 如何在一个窗口中绘制两个图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   

我使用 distr 来形成以下分配:库(distr)

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

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

解决方案

使用ggplot



您可以使用 stat_function



例如

 #定义您感兴趣的x值范围的数据
DF< -data.frame( x = c(1,8))
ggplot(DF,aes(x = x))+
stat_function(fun = d(G1),aes(color ='G1'))+
stat_function(fun = d(G2),aes(color ='G2'))+
scale_colour_manual('Distribution',
values = setNames(c('red','blue'), c('G1','G2')))


使用base



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



您需要设置 mfrow (或 mfcol ),然后设置 mfColRow = FALSE 无线



例如:

  par(mfrow = (G2,mfColRow = F)

$($)
plot b
$ b


I am using distr to form the following distributions:

library(distr)

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

now in order to compare these two distributions I need to plot them in one window, but I don't know how. I tried ggplot but apparently it does not work with gamma function.

解决方案

Using ggplot

you can use stat_function

eg

# 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')))

Using base

The help file for distr::plot shows how to combine plots.

You need to set mfrow (or mfcol) yourself, then set mfColRow =FALSE within the plot call.

eg:

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

这篇关于distr包 - 如何在一个窗口中绘制两个图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆