Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing x axis tick labels in R using ggplot2 [duplicate]

Tags:

r

ggplot2

boxplot

How can I change the names of my x axis labels in ggplot2? See below:

ggbox <- ggplot(buffer, aes(SampledLUL, SOC)) + geom_boxplot()  ggbox <- ggbox + theme(axis.text.x=element_text(color = "black", size=11, angle=30, vjust=.8, hjust=0.8))   ggbox<- ggbox + labs(title = "Land cover Classes") + ylab("SOC (g C/m2/yr)") + xlab("Land cover classes") 

The above code creates the following figure: enter image description here

I would like to be able to capitilize the first letter of these classes (i.e Crop, as opposed to crop).

I've tried the code below but not sure where to put it and exactly what function to use. labels = c("Citrus", "Crop", "Cypress Swamp", ..........)

(I'm using windows 7, Rstudio)

like image 436
derelict Avatar asked Dec 11 '13 20:12

derelict


People also ask

How do I change x labels in ggplot2?

To alter the labels on the axis, add the code +labs(y= "y axis name", x = "x axis name") to your line of basic ggplot code. Note: You can also use +labs(title = "Title") which is equivalent to ggtitle .

How do I change the x-axis tick marks in R?

Option 1. Set xaxt = "n" and yaxt = "n" to remove the tick labels of the plot and add the new labels with the axis function. Note that the at argument sets where to show the tick marks.

How do you change the x and y axis in ggplot2?

Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.


1 Answers

create labels:

 SoilSciGuylabs <- c("Citrus", "Crop", "Cypress Swamp") 

then add:

+ scale_x_discrete(labels= SoilSciGuylabs) 
like image 93
user1317221_G Avatar answered Sep 22 '22 11:09

user1317221_G