如何为该情节添加图例?

时间:2021-04-19 09:02:24

标签: r ggplot2 plot legend

我正在尝试绘制此图,但无法添加解释线条颜色的图例。有人能帮我吗? 我正在使用 ggplot,这是到目前为止的代码:

library(readxl)
COB_HH <- read_excel("Downloads/COB_HH.xls", 
                     col_types = c("date", "numeric", "numeric", 
                                   "numeric", "numeric", "numeric", 
                                   "numeric"))

par(bty = "l")
plot ((COB_HH), lty = 2, pch = 19, col = "red", main = "COB for Corporations")
grid()

ggplot(COB_HH, aes(x= Date, y= COB)) + 
  geom_line(aes(x=Date, y= Germany), col = "black") +
  geom_line(aes(x=Date, y= Spain), col = "yellow") +
  geom_line(aes(x=Date, y= Greece), col = "blue") +
  geom_line(aes(x=Date, y= Ireland), col = "green") +
  geom_line(aes(x=Date, y= Italy), col = "red") +
  geom_line(aes(x=Date, y= Portugal), col = "purple") +  
  ggtitle("COB for Households",subtitle = "Cost of borrowing for Households")  + ylab(NULL) 

0 个答案:

没有答案
相关问题