dismo icon indicating copy to clipboard operation
dismo copied to clipboard

gbm.plot: y axis values reported incorrectly to plot.default?

Open SimonDedman opened this issue 2 years ago • 0 comments

Hi folks, sorry for the multiple recent messages.

In my package, I call gbm.plot, and was looking to add a simple abline at 0:

png(filename = paste0("./",names(samples[i]),"/Gaus_Best_line_",as.character(get(Gaus_Best_Model)$gbm.call$predictor.names[p]),".png"),
            width = 4*480, height = 4*480, units = "px", pointsize = 80, bg = "white", res = NA, family = "", type = pngtype)
        par(mar = c(2.3,5,0.3,0.6), fig = c(0,1,0,1), las = 1, lwd = 8, bty = "n", mgp = c(1.25,0.5,0), xpd = NA)
        gbm.plot(get(Gaus_Best_Model),
                 variable.no = p,
                 n.plots = 1,
                 common.scale = FALSE, #added to try to get cvs values to match pngs
                 smooth = smooth, # typically TRUE
                 rug = TRUE,
                 write.title = FALSE,
                 y.label = "",
                 x.label = NULL,
                 show.contrib = TRUE,
                 plot.layout = c(1, 1))
        abline(a = 0, b = 0, lty = 2, lwd = 20) # https://github.com/SimonDedman/gbm.auto/issues/7
        mtext("Marginal Effect", side = 2, line = 4.05, las = 0)

I initially tried abline(h=0) which had the same result: regardless of input - which is otherwise plotting great - the abline is at the bottom:

Gaus_Best_line_X CC

In this example, Y crosses 0 both in the raw data, as well as when centred:

image

Somewhat regardless, all data should be centred due to these lines from gbm.plot:

response.matrix <- gbm::plot.gbm(gbm.object, k, return.grid = TRUE)
responses[[j]] <- response.matrix[, 2] - mean(response.matrix[, 2])
plot(predictors[[j]], responses[[j]], type = "l",  xlab = x.label, ylab = y.label, ...)

I've looked and looked and can't for the life of me work out why this isn't working. A simple abline call works fine:

plot(-5:5, -5:5)
abline(h=0)

On a whim, I tried adding ablines at 0, 0.5, 1, 2, 5, 10, 100, and get the following - the lines are in the same place for every plot regardless of changing Y axis scales, suggesting the underlying plot seemingly isn't operating on the standard plot scale somehow?

Gaus_Best_line_X CC

Any ideas or gut feelings very much appreciated.

SimonDedman avatar May 18 '23 20:05 SimonDedman