To rotate axis labels in R, use the las argument that is a numeric value indicating the orientation of the tick mark labels and any other text added to a plot after its initialization.
The options are as follows:
Parallel to the axis (the default, 0),
Perpendicular to the axis (2),
barplot(mtcars$cyl, col=mtcars$gear, las = 1)
If you want to learn more about R programming watch this tutorial on Introduction to Data Science with R