要将纵坐标的坐标范围更改为 -60 到 60,你可以使用 'coord_cartesian' 函数来限制纵坐标轴的可见范围。

以下是修改后的代码示例:

# 首先我们要将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 = 'Boxplot of Adjusted ISQ Scores',
       x = expression(bold('Group')),
       y = expression(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'),
        axis.title.x = element_text(color = 'black', size = 12, face = 'bold'),
        axis.title.y = element_text(color = 'black', size = 12, face = 'bold')) +
  guides(fill = FALSE) +
  coord_cartesian(ylim = c(-60, 60))

在上面的代码中,我们添加了 'coord_cartesian(ylim = c(-60, 60))' 来将纵坐标轴的可见范围限制在 -60 到 60 的范围内。

通过以上修改,你可以将纵坐标的坐标范围更改为 -60 到 60。

R语言 ggplot2 图表:如何设置纵坐标范围为 -60 到 60

原文地址: https://www.cveoy.top/t/topic/cw1u 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录