【问题标题】:Change or modify x axis tick labels in R using ggplot2 [duplicate]使用ggplot2更改或修改R中的x轴刻度标签[重复]
【发布时间】:2022-06-15 22:22:33
【问题描述】:

如何更改 ggplot2 中 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\")

上面的代码创建了下图:

我希望能够将这些类的第一个字母大写(即作物,而不是作物)。

我试过下面的代码,但不知道把它放在哪里以及到底要使用什么功能。 labels = c(\"Citrus\", \"Crop\", \"Cypress Swamp\", ..........)

(我使用的是 Windows 7,Rstudio)

标签: r ggplot2 boxplot


【解决方案1】:

创建标签:

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

然后加:

+ scale_x_discrete(labels= SoilSciGuylabs)

【讨论】:

  • 我用它来将连续变量屏蔽为分类变量,这样我就可以使用 geom_line。为了使标签出现,我需要先设置中断。我用scale_x_continuous(breaks=seq(1,12,1),labels=my_labels)。只是注意到这里以防它帮助别人。
猜你喜欢
  • 2013-12-30
  • 1970-01-01
  • 1970-01-01
  • 2020-03-29
  • 2018-05-27
  • 1970-01-01
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多