如何使用 ggplot 更改条形图中的 x 轴标签以使其更具体

问题描述 投票:0回答:0

我想更改我的 x 轴,使其具有更具体的值。我希望它仍然从 0 开始,但以 0.5 步长达到 4 或 5。我该怎么做呢?我只知道重命名x轴的标签。我尝试了命令 axis = FALSE 然后 axis (1, at = seq (...)) 等,但这不起作用。

这是我到目前为止的代码:

library(ggplot2)

ggplot(
  data.m,
  aes(
    y = reorder(Category, ifelse(variable == "Teacher", value, 0), FUN = sum),
    x = value
  )
) +
  geom_col(aes(fill = variable),
    position = position_dodge(width = 0.6), width = .6
  ) +
  geom_text(aes(label = value, group = variable),
    hjust = -0.2, size = 2.5,
    position = position_dodge(width = 0.6)
  ) +
  scale_x_continuous(expand = c(0, 0, .05, 0)) +
  scale_fill_brewer(palette = "Blues", breaks = rev) +
  theme_classic() +
  labs(title = "Students and Teachers", x = "Category", y = "Means", fill = NULL)
ggplot2 axis-labels x-axis
© www.soinside.com 2019 - 2024. All rights reserved.