title: R xgboost importance plot with many features
body: <p>I am trying out the Kaggle housing prices challenge : <a href="https://www.kaggle.com/c/house-prices-advanced-regression-techniques" rel="nofollow noreferrer">https://www.kaggle.com/c/house-prices-advanced-regression-techniques</a></p>
  
  <p>Here is the script I wrote</p>
  
  <pre><code>train    &lt;- read.csv("train.csv")
  train$Id &lt;- NULL
  previous_na_action = options('na.action')
  options(na.action = 'na.pass')
  sparse_matrix &lt;- sparse.model.matrix(SalePrice~.-1,data = train)
  options(na.action = previous_na_action)
  model &lt;- xgboost(data = sparse_matrix, label = train$SalePrice, missing = NA, max.depth = 6, eta = 0.3, nthread = 4, nrounds = 16, verbose = 2, objective = "reg:linear")
  importance &lt;- xgb.importance(feature_names = sparse_matrix@Dimnames[[2]], model = model)
  print(xgb.plot.importance(importance_matrix = importance))
  </code></pre>
  
  <p>The data has over 70 features, I used <code>xgboost</code> with <code>max.depth</code> = 6 and <code>nrounds</code> = 16.</p>
  
  <p>The importance plot i am getting is very messed up, how do i get to view only the top 5 features or something.</p>
  
  <p><a href="https://i.stack.imgur.com/iUvZv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iUvZv.png" alt="enter image description here"></a></p>