I am wondering why the following bit of code doesn’t produce the two plots one below the other.
data(mtcars)
library(randomForest)
mtcars.rf <- randomForest(mpg ~ ., data=mtcars, ntree=1000, keep.forest=FALSE,
importance=TRUE)
png("rf1.png", width=6, height=6, units="in", res=100)
par(mfcol=c(2,1))
varImpPlot(mtcars.rf)
plot(mtcars.rf, log="y")
dev.off()
This just produces
with a blank second row.
The problem is that varImpPlot redefines the plotting area, and then resets it to the previous value. This means it acts as if you called
par(mfcol=c(2,1))after thevarImpPlotline. If you extract the varImpPlot plotting data you can plot the two dotcharts yourself (you can uselayoutrather thanparto split the plotting area into different shaped regions):