Reputation: 15
I am trying to arrange 49 plots into a 7x7 grid but the plots will not plot correctly using qplot
.
a <- c(0.1,0.5,1,2,5,10,100)
b <- c(0.1,0.5,1,2,5,10,100)
for(m in 1:7)
{
for(n in 1:7)
{
#Q4. Assigning variables for moving averages
assign(paste("ma_a",m,"b",n,sep=""),c())
for(i in 1:1000)
{
.GlobalEnv[[paste("ma_a",m,"b",n,sep="")]] <- c(.GlobalEnv[[paste("ma_a",m,"b",n,sep="")]],mean(rgamma(i,a[m],b[n])))
}
#Plotting moving averages
plot(1:1000,.GlobalEnv[[paste("ma_a",m,"b",n,sep="")]]
,type="l"
,xlab="X"
,main=paste("Moving Average at","Shape=",a[m],"Scale=",b[n])
,ylab="Average"
)
}
}
When like this the plots work correctly but after trying to arrange them into a grid, I realized I had to use qplot()
in order for grid.arrange()
to work. It says I cannot use a numerical vector so I have tried using a data frame with 2 columns, first being 1:1000 and the 2nd being the moving average but this will still not plot correctly and just gives a grey box covering all of the plot.
Upvotes: 0
Views: 314
Reputation: 9656
Since you are not using grid based graphics system, you can use par()
to arrange your figures.
See if this works:
a <- c(0.1,0.5,1,2,5,10,100)
b <- c(0.1,0.5,1,2,5,10,100)
par(mfrow=c(7,7), mar=c(2,2,2,0))
for(m in 1:7)
{
...
Upvotes: 1