0

I was trying to combine gbm.plot.fit and plot.gbm from different gbm models. Here is my example code:

#----------------------ask on stackexchange----------------------------#
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")

library(gbm)
library(dismo)

full.model<- gbm.step(data=mydata,gbm.x = 2:4,gbm.y = 1,family = "bernoulli", tree.complexity = 5,learning.rate = 0.005, bag.fraction = 0.5)

fit1 <- gbm.step(data=mydata,gbm.x = 2,gbm.y = 1,family = "bernoulli", tree.complexity = 5,learning.rate = 0.005, bag.fraction = 0.5)

a=gbm.plot.fits(full.model,v="gre")

b=plot.gbm(full.model,i.var="gre")

c=gbm.plot.fits(fit1)

d=plot.gbm(fit1)

grid.arrange(a, b, c, d, ncol=2, nrow =2)

The error message is:

Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, : input must be grobs!

Can someone tell me what might go wrong with my code?

eipi10
  • 91,525
  • 24
  • 209
  • 285
  • It looks like those functions use base graphics, which does not create grobs (graphical objects). (`grid` graphics functions, such as those available in `ggplot2`, `lattice` or `grid` itself, create grobs.) With base graphics, you can lay out your plots by running, say, `par(mfrow=c(2,2))` before plotting, or for finer control, look at the `layout` function. – eipi10 Oct 14 '15 at 21:21
  • You might get more response if you posted sufficient code to create an actual object. – IRTFM Oct 15 '15 at 01:03
  • @eipi10 Thanks for your comments. par(mfrow=c(2,2)) wouldn't work here. That was my initial code and the reason why I switched to use the grid.arrange – Charlotte Deng Oct 15 '15 at 21:48
  • @BondedDust Thanks! Please see my updated post!! – Charlotte Deng Oct 15 '15 at 21:48
  • After looking at the objects and code it appears that `plot.gbm` uses lattice plotting while `dismo::gbm.plot.fits` uses base plotting. You will probably need to use the 'gridBase'-package to mix the two plotting paradigms, and because `plot.gbm` does not return the grid-values you will probably need to either hack that code or figure out how to open a viewPort and "print()" into it. I'm wondering if just printing to png() files and assembling afterwards might be easier. – IRTFM Oct 15 '15 at 22:41

0 Answers0