2013-12-11 6803 views
7

如何更改ggplot2中x軸標籤的名稱? 見下文:使用ggplot2在R中更改x軸刻度標籤

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") 

上面的代碼建立下圖: enter image description here

我想能夠capitilize這些類的第一個字母(即作物,相對於裁剪)。

我試過了下面的代碼,但不知道放在哪裏以及使用哪個函數。 labels = c("Citrus", "Crop", "Cypress Swamp", ..........)

(我使用Windows 7,Rstudio)

回答

9

創建標籤:

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

然後加入:

+ scale_x_discrete(labels= SoilSciGuylabs)