使用ggplot2更改R中的x轴刻度标签 [英] Changing x axis tick labels in R using ggplot2
问题描述
如何在ggplot2中更改我的x轴标签的名称?
见下面:
$ g $ 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 =土地覆盖类别)+ ylab(SOC(g C / m2 / yr))+ xlab(土地覆盖类别)
上面的代码创建了下图:
我希望能够将这些类的第一个字母(即Crop,反对作物)。
我试过了下面的代码,但不知道该把它放在哪里,以及使用哪个函数。
labels = c(Citrus,Crop,Cypress Swamp,..........)
(我正在使用Windows 7,Rstudio)
(柑橘,作物,赛普拉斯沼泽)
SoilSciGuylabs < c>
然后添加:
+ scale_x_discrete( labels = SoilSciGuylabs)
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:
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)
create labels:
SoilSciGuylabs <- c("Citrus", "Crop", "Cypress Swamp")
then add:
+ scale_x_discrete(labels= SoilSciGuylabs)
这篇关于使用ggplot2更改R中的x轴刻度标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!