是否可以向 geom_line() 行添加標簽以更新圖例中的系列標簽?
我希望它顯示 #eb6b63 -> Revenue #407edb -> Profit 而不是顯示十六進制顏色代碼的圖例
ggplot(RevGroup, aes(x=MonthYear))
geom_line(aes(y=sum_rev_month, color = '#eb6b63'))
geom_line(aes(y=sum_prof_month, color = '#407edb'))
myTheme
labs(colour = "Amount($)", title = 'Yearly Revenue and Profit trends', x = 'Year', y = 'Amount($)')
上面的代碼產生下面的圖。
任何幫助將不勝感激。

uj5u.com熱心網友回復:
嘗試使用scale_color_manual:
ggplot(RevGroup, aes(x=MonthYear))
geom_line(aes(y=sum_rev_month, color = "Revenue"))
geom_line(aes(y=sum_prof_month, color = "Profit"))
myTheme
labs(colour = "Amount($)", title = 'Yearly Revenue and Profit trends', x = 'Year', y = 'Amount($)')
scale_color_manual(values = c('#eb6b63', '#407edb'))
通常最好將您的資料重塑為長格式,以便您可以color使用變數而不是手動設定美感。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/343314.html
上一篇:ggplot標簽輪廓與sf物件
