简体   繁体   English

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

[英]Customize lines in ggplot linegraph with multiple lines

I build this graph:我构建了这个图表:

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())
 

在此处输入图像描述

But instead of changing the style of the lines, the styling just appears in the legend.但不是改变线条的样式,样式只是出现在图例中。

Thanks in advance for any kind of help.提前感谢您的任何帮助。

cheers干杯

take them out of the aes:将它们从 aes 中取出:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM