AliCivil
AliCivil

Reputation: 2053

distr package-how to draw two plots in one window?

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.

Upvotes: 1

Views: 151

Answers (1)

mnel
mnel

Reputation: 115505

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

enter image description here

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)

enter image description here

Upvotes: 5

Related Questions