使用多条线自定义 ggplot 线图中的线

Customize lines in ggplot linegraph with multiple lines

我构建了这张图:

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

df_ebf <- df_ebf %>%
  map_df(rev)


ggplot(data=df_ebf, aes(x=forcats::fct_inorder(Skalen), y=Werte, group="")) +
  geom_line(aes(y = Werte, color = "#003560")) +
  geom_line(aes(y = SD_plus, color = "#8DAE10", linetype = "dashed")) +
  geom_line(aes(y = SD_minus, color = "#8DAE10",linetype = "dashed")) +
  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), labels = paste0(0:6, "\n", labels.minor), sec.axis = sec_axis(~.x, breaks = 0:6)) +
  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())
 

但是并没有改变线条的样式,样式只是出现在图例中。

将它们从 aes 中取出:

aes(...), color="..", linetype=".."