Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating x axis labels in R for barplot

I am trying to get the x axis labels to be rotated 45 degrees on a barplot with no luck. This is the code I have below:

barplot(((data1[,1] - average)/average) * 100,         srt       = 45,         adj       = 1,         xpd       = TRUE,         names.arg = data1[,2],         col       = c("#3CA0D0"),         main      = "Best Lift Time to Vertical Drop Ratios of North American Resorts",         ylab      = "Normalized Difference",         yaxt      = 'n',         cex.names = 0.65,         cex.lab   = 0.65) 
like image 398
David Avatar asked Apr 23 '12 18:04

David


People also ask

How do I rotate X-axis labels in Barplot in R?

Method 1: Using barplot() To display all the labels, we need to rotate the axis, and we do it using the las parameter. To rotate the label perpendicular to the axis we set the value of las as 2, and for horizontal rotation, we set the value as 1. Secondly, to increase the font size of the labels we use cex.

How do you rotate the X-axis labels?

Rotate X-Axis Tick Labels in Matplotlib There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax.

How do you name the X-axis in a Barplot in R?

To set X, Y axes labels for Bar Plot drawn using barplot() function, pass the required label values for xlab parameter and ylab parameter in the function call respectively. xlab parameter is optional and can accept a value to set X-axis label for the bar plot.


1 Answers

use optional parameter las=2 .

barplot(mytable,main="Car makes",ylab="Freqency",xlab="make",las=2) 

enter image description here

like image 93
Michael Z Avatar answered Sep 22 '22 15:09

Michael Z