Skip to content

Commit 6383757

Browse files
authored
[R] allow xgb.plot.importance() calls to fill a grid (#6294)
1 parent d261ba0 commit 6383757

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

R-package/R/xgb.plot.importance.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ xgb.plot.importance <- function(importance_matrix = NULL, top_n = NULL, measure
9999
}
100100

101101
if (plot) {
102-
op <- par(no.readonly = TRUE)
103-
mar <- op$mar
102+
original_mar <- par()$mar
103+
104+
# reset margins so this function doesn't have side effects
105+
on.exit({par(mar = original_mar)})
106+
107+
mar <- original_mar
104108
if (!is.null(left_margin))
105109
mar[2] <- left_margin
106110
par(mar = mar)
@@ -109,11 +113,6 @@ xgb.plot.importance <- function(importance_matrix = NULL, top_n = NULL, measure
109113
importance_matrix[rev(seq_len(nrow(importance_matrix))),
110114
barplot(Importance, horiz = TRUE, border = NA, cex.names = cex,
111115
names.arg = Feature, las = 1, ...)]
112-
grid(NULL, NA)
113-
# redraw over the grid
114-
importance_matrix[rev(seq_len(nrow(importance_matrix))),
115-
barplot(Importance, horiz = TRUE, border = NA, add = TRUE)]
116-
par(op)
117116
}
118117

119118
invisible(importance_matrix)

0 commit comments

Comments
 (0)