Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manipulate y-axis text labels in R varImpPlot?

Tags:

r

The following sample resembles my dataset:

require(randomForest)

alpha = c(1,2,3,4,5,6)
bravo = c(2,3,4,5,6,7)
charlie = c(2,6,5,3,5,6)
mydata = data.frame(alpha,bravo,charlie)

myrf = randomForest(alpha~bravo+charlie, data = mydata, importance = TRUE)

varImpPlot(myrf, type = 2)

I cannot seem to control the placement of the y-axis labels in varImpPlot. I have tried altering the plot parameters (e.g. mar, oma), with no success. I need the y-axis labels shifted to the left in order to produce a PDF with proper label placement.

How can I shift the y-axis labels to the left?

like image 701
Borealis Avatar asked Feb 15 '13 17:02

Borealis


People also ask

How do you change the Y-axis labels in R?

The easiest way to change the Y-axis title in base R plot is by using the ylab argument where we can simply type in the title. But the use of ylab does not help us to make changes in the axis title hence it is better to use mtext function, using which we can change the font size, position etc.

How do I change the values of an axis in R?

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do I change the size of axis labels in R?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.

How do I remove Y-axis labels in R?

When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.


1 Answers

I tried to use adj parameter but it produces a bug. As varImpPlot , use dotchart behind, Here a version using lattice dotplot. Then you can customize you axs using scales parameters.

imp <- importance(myref, class = NULL, scale = TRUE, type = 2)
dotplot(imp, scales=list(y =list(cex=2,
                                       at = c(1,2),
                                       col='red',
                                       rot =20,
                                       axs='i') ,
                               x =list(cex=2,col='blue')) )

enter image description here

like image 195
agstudy Avatar answered Sep 28 '22 18:09

agstudy