R语言ggplot2图中如何加粗并设置文本颜色
要将图中的 'Group' 和 'Adjusted ISQ Score' 文本加粗且颜色设置为黑色,你可以在 labs 函数中使用 bold() 函数来设置文本的字体加粗,然后使用 theme 函数中的 axis.text.x 和 axis.text.y 参数来设置文本的颜色为黑色。
以下是修改后的代码示例:
# 首先我们要将group字段的数据类型改为因子型,并命名相应的水平
comparison_hp$group <- factor(comparison_hp$group,
levels = c(1, 2),
labels = c("Patient", "Healthy"))
# 制作箱线图
ggplot(comparison_hp, aes(x = factor(group), y = ISQ_adjusted)) +
geom_boxplot() +
scale_fill_manual(values = c("black", "grey"),
name = "Group",
labels = c("Patient", "Healthy")) +
labs(title = bquote("Boxplot of Adjusted ISQ Scores"),
x = bquote(bold("Group")),
y = bquote(bold("Adjusted ISQ Score"))) +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.x = element_text(color = "black", size = 12, face = "bold"),
axis.text.y = element_text(color = "black", size = 12, face = "bold")) +
guides(fill = FALSE)
在上面的代码中:
- 在
labs函数中,使用bquote函数将文本内容包裹起来,并在需要加粗的地方使用bold函数来设置字体加粗。 - 在
theme函数中,使用axis.text.x参数和axis.text.y参数分别设置横坐标轴和纵坐标轴标签的颜色为黑色,字体大小为12,字体加粗。
通过以上修改,你可以将图中的 'Group' 和 'Adjusted ISQ Score' 文本加粗且颜色设置为黑色。
原文地址: https://www.cveoy.top/t/topic/cwD8 著作权归作者所有。请勿转载和采集!