0

I have plotted the importance matrix in xgboosot and I want to make the text bigger, how do I do that?

gg <- xgb.ggplot.importance(importance_matrix = a,top_n = 15)
HilaD
  • 871
  • 5
  • 15
  • 23
  • Possible duplicate of [Changing font size and direction of axes text in ggplot2](https://stackoverflow.com/questions/13297995/changing-font-size-and-direction-of-axes-text-in-ggplot2) – thc Aug 14 '17 at 23:05
  • @thc I'm asking something completely different, If I could use the direct ggplot2 code I would. – HilaD Aug 14 '17 at 23:18
  • The xgboost plot function returns a ggplot object, so you can modify it in the same way as any other ggplot. – thc Aug 14 '17 at 23:23
  • @thc I tried few times and couldn't.. can you write here working code? – HilaD Aug 15 '17 at 00:06
  • So what happened to the sklearn problem? –  Aug 30 '17 at 10:45

1 Answers1

1

Use theme() to increased the font size.

Below, I have given a minimum reproducible example;

# Load library
library(ggplot2)
require(xgboost)
# load data
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
train <- agaricus.train
test <- agaricus.test
# create model
bst <- xgboost(data = train$data, label = train$label, max.depth = 2,
               eta = 1, nthread = 2, nround = 2, objective = "binary:logistic")
# importance matrix
imp_matrix <- xgb.importance(colnames(agaricus.train$data), model = bst)
# plot 
xgb.ggplt<-xgb.ggplot.importance(importance_matrix = imp_matrix, top_n = 4)
# increase the font size for x and y axis
xgb.ggplt+theme( text = element_text(size = 20),
  axis.text.x = element_text(size = 15, angle = 45, hjust = 1))

Increased Font Size in Feature Importance Plot

Use ?theme to see the list of parameters you can modify.

mnm
  • 1,962
  • 4
  • 19
  • 46