簡體   English   中英

在geom_line(ggplot2)中為一種線型着色

[英]Coloring one linetype in geom_line (ggplot2)

在下面的線條圖鏈接中,我顯示了超過10場比賽的狀態統計數據,其中不同的線型指示年份。 有沒有一種方法可以僅在2016年產品線中添加顏色以使其突出? 我嘗試將scale_manual_color與不同顏色值的向量一起使用,但這沒用。 以下也是我正在使用的代碼。 感謝您的幫助。

ggplot(df, aes(x = games1, y = diff_cum, group = Year, linetype = Year)) + 
    geom_line(size = 1) + 
    theme_bw()

在此處輸入圖片說明

您實際上必須添加一種color (或多種colour

ggplot(df, 
  aes(
     x = games1, 
     y = diff_cum, 
     group = Year, 
     color = Year, # This right here!
     linetype = Year)) + 
  geom_line(size = 1) + 
  theme_bw() + 
  scale_color_manual(values = c("my","colours","for","year"))

您可以使用ifelse設置aes組

ggplot(mtcars, aes(x = disp, y = hp, group = cyl)) +
  geom_line(aes(color = ifelse(cyl == 6, "6", "not6"))) +
  scale_color_manual(values = c("red", "black"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM