Reputation: 2053
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
Reputation: 115505
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')))
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)
Upvotes: 5