1

I am using Random Forest, and now I need to plot the importance plot. I achieved that by implementing the code:

data <- read.table("sample.matrix", header = T, sep = ",", check.names=FALSE)
x_num <- data[6:ncol(data)] 
x_feature <- data$Feature
resul_rf <- randomForest(x_num, x_feature ,importance=TRUE, proximity=TRUE, ntree=500) 
varImpPlot(resul_rf , type=1, pch=19, col="black", cex=.8) 

This code above will plot graph importance from random Forest analysis. But how can I save this image in disk programmatically like in ggplot where we specify:

ggsave(file="namefile.jpg", width=500, height=700)

I've searched about it but unfortunately, I did not find anything. Can someone help me out with that?. I need to save the plot as jpg and pdf file.

Erick
  • 147
  • 2
  • 12
  • Save it how exactly? As a pdf? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 08 '19 at 15:17
  • I also don't understand this question. What's wrong with good old: `png("foo.png"); ...;dev.off()`? – pogibas Jan 08 '19 at 15:18
  • @PoGibas I edited that question in order to provide better information, but I need to save the plot generated by varImpPlot function as jpg and pdf. – Erick Jan 08 '19 at 16:01
  • @PoGibas no this solution does not fit in my case. The plot generated by varImpPlot function is different (aesthetically and the axes are different) of graph generated by plot function. I want to save the varImpPlot plot as it is. – Erick Jan 08 '19 at 16:15
  • 2
    Have you tried any of the solutions? The one that saves a pdf? – pogibas Jan 08 '19 at 16:17
  • 1
    Hey It worked man. Sorry, I am still learning R. Sorry borrow you. – Erick Jan 08 '19 at 16:21
  • @Erick which solution worked? – Herman Toothrot Sep 21 '22 at 12:05

0 Answers0