r - ggplot R中的X轴子标签
问题描述
我有以下 ggplot 代码呈现下面的箱形图。
ggplot(comparisonData, aes(Group,score)) +
geom_boxplot(notch = TRUE, varwidth = TRUE, aes(colour = Group)) +
geom_jitter(width = 0.2, aes(colour = Group)) +
theme(legend.position = "none") +
labs(title="User Engagement Score", x="Condition", y="Score (max 140)")
在此图中,我希望将 x 轴上的第 1 组和第 2 组重命名为“隐形”和“非隐形”,但我无法找到这样做的方法。是否可以不更改数据中的组名?
解决方案
您可以通过比例更改标签,例如
library(tidyverse)
library(palmerpenguins)
penguins %>%
na.omit() %>%
mutate(species = factor(ifelse(species == "Adelie", 1, 2))) %>%
ggplot(aes(x = species, y = bill_length_mm)) +
geom_boxplot(aes(colour = species), notch = TRUE, varwidth = TRUE) +
geom_jitter(width = 0.2, aes(colour = species)) +
theme(legend.position = "none") +
labs(title="User Engagement Score", x="Condition", y="Score (max 140)") +
scale_x_discrete(label = c("Stealth", "Non-stealth"))
推荐阅读
- r - r - 列表列数据框和行号的条件
- pascal - 任何人都可以告诉我这个功能的目的吗?
- java - 显示上升数字的简单时钟
- ios - Is it possible MARK: (#pragma mark) in Localizable.string 文件
- java - 安卓 | 充气按钮不起作用
- angular - 延迟加载而不更改angular5中的url
- python - 在 Pandas 类别频率表中未显示 0 计数
- angular - 排序不工作的角材料设计表
- postgresql - 如何在 DB PostgreSql 中禁用嵌套触发器?
- auth0 - DialogFlow/Actions:允许 Google Assistant 用户通过 Actions 应用在 Google 日历中创建事件