如何在图例上绘制线条名称而不使用颜色,线型或形状

时间:2019-10-30 12:08:53

标签: r ggplot2

在此绘图中,我想在图例上显示红色实线的名称(“ c”)。既然那条线必须是“红色”颜色,“实心”并且没有“点形”,该怎么办?

在这种情况下,如何在图例上显示'c'行的名称?

function "Pilot::Pilot(const Pilot &)" (declared at line 50 of "C:\Users\mjova\source\repos\Project1\Project1\Pilot.h") cannot be referenced -- it is a deleted function   Project1    C:\Users\mjova\source\repos\Project1\Project1\Planes.h  36

reprex package(v0.3.0)于2019-10-30创建

1 个答案:

答案 0 :(得分:1)

这是一种使用is_special列思想的方法。

df_all = rbind(df1, df2)
df_all$is_special = ifelse(df_all$line_label == "c", "y", "n")

ggplot(data = df_all, aes(x = year, y = value, color = line_label)) +
  geom_line(aes(linetype = line_label, size = is_special, alpha = is_special)) +
  geom_point(aes(shape = line_label), size = 3) +
  scale_color_manual(values=c("#BFBFBF", "#173C70", "#DA2537")) +
  scale_linetype_manual(values=c("solid", "dashed", "solid")) +
  scale_size_manual(values = c("n" = 1, "y" = 2), guide = "none") +
  scale_alpha_manual(values = c("n" = 1, "y" = 0.8), guide = "none") +
  scale_x_continuous(breaks=seq(2010, 2012, by = 1)) 

enter image description here