-1

我建立了这个情节:

df_ebf <- df_ebf %>%
  map_df(rev)

labels.minor <- c("nie","selten","manchmal", "mehrmals", "oft", "sehr oft", "immerzu")

ggplot(data=df_ebf, aes(x=forcats::fct_inorder(Skalen), y=Werte, group="")) +
  geom_line(color = "#003560") +
  geom_point(color = "#003560") +
  coord_flip() +
  labs(x="EBF-Skalen") +
  scale_y_continuous(limits = c(0, 6), breaks = c(0,1,2,3,4,5,6), sec.axis = dup_axis(),expand = c(0,0)) +
  scale_x_discrete(expand = c(0,0)) +
  theme(panel.grid.major.y = element_blank(),panel.grid.minor.x = element_blank(),axis.line.x = element_line(size = 1, colour = "black", linetype=1),axis.title=element_blank())

在此处输入图像描述

现在我想用labels.minor在较低的x轴下方添加第二个x轴。

我在论坛中寻找解决方案时发现了这个这个,但它不适用于我的情况。

4

1 回答 1

2

如果您labels.minor位于中断的确切位置,则只需将标签与换行符粘贴在一起即可。下面的例子:

library(ggplot2)

df <- data.frame(
  x = runif(10, min = 0, max = 6),
  y = letters[1:10]
)

labels.minor <- c("nie","selten","manchmal", "mehrmals", "oft", "sehr oft", "immerzu")

ggplot(df, aes(x, y)) +
  geom_path(aes(group = -1)) +
  geom_point() +
  scale_x_continuous(limits = c(0, 6), breaks = 0:6,
                     labels = paste0(0:6, "\n", labels.minor),
                     sec.axis = sec_axis(~.x, breaks = 0:6))

reprex 包于 2021-04-10 创建(v1.0.0)

于 2021-04-10T12:10:36.797 回答