在 R 中的 ggplot2 图中的两个离散值之间增加 space

Increase space between two discrete values in a ggplot2 plot in R

我想弄清楚如何在 x 轴上两个离散值之间的图中添加 space。例如,在下面的图中,我想在 Setosa 和 Versicolor 之间保持相同的间距,但在图中(不是轴标签)在 Versiolor 和 Virginica 之间添加 space。

data(iris)

library(ggplot2)
ggplot(data = iris, aes(x = Species, y = Sepal.Width)) +
  geom_point() 

据我所知,最简单的方法是使用自定义分隔符和标签将轴设为数字:

library(ggplot2)

iris %>%
  mutate(Species2 = ifelse(Species == "virginica", 4, as.numeric(Species))) %>%
  ggplot(aes(x = Species2, y = Sepal.Width)) +
  geom_point() +
  scale_x_continuous(breaks = c(1, 2, 4), labels = levels(iris$Species),
                     expand = c(0, 1), name = "Species",
                     minor_breaks = NULL)