every one.
I have a function g(mua=1) which will plot a ggplot2 figure like this ( to illustrate the concept of POWER):
But I want plot 5 figures with different parameter. Like this
for(mua in c(0, .5, 1, 1.5, 2))
{
g(mua)
}
And I wish the figure is like this
So, is that possible? because I know in base system, I could call par(mfrow=c(2,3)).
here is all the code I have now
g <- function(mua=1.2){
mu0=0
ggplot(data.frame(x=c(-4.5, 4.5)),
aes(x)
) +
stat_function(fun=dnorm,args = list(mean=mu0), size = 1.5) +
stat_function(fun=dnorm,args = list(mean=mua), size = 1.5) +
geom_area(stat = "function", fun = dnorm,args=list(mean=mua), fill = "red",
xlim = c(qnorm(1-0.025,mean = mu0), 5),
alpha = 0.4) +
annotate(geom = "text",x=mu0,y=0,label="mu0") +
annotate(geom = "text",x=mua,y=0,label="mua") +
annotate(geom = "text",x=qnorm(1-0.025,mean = mu0),
y=0,label=round(qnorm(1-0.025,mean = mu0),2))
}
# something like "par(mfrow=c(4,1))"
for(i in seq(0,2,by=0.5)){
g(i)
}