我希望每个国家/地区的线条与我手动设置的颜色相同。即。瑞典=红色,美国=蓝色,加拿大=绿色。
如何最好地做到这一点?
library(tidyverse)
df <- tibble(
date = rep(c(as.Date("1995-01-01"), as.Date("1995-01-01"), as.Date("1996-01-01"), as.Date("1996-01-01")), 3),
decile = rep(c("d1", "d2"), 6),
income = c(10, 30, 15, 35, 50, 60, 70, 80, 90, 100, 110, 120),
country = c(rep("Sweden", 4), rep("Canada", 4), rep("USA", 4))
)
g <- ggplot(df, aes(x = date, y = income)) +
geom_line(aes(colour = decile), size = 2) +
scale_color_manual(values = c("red", "green", "blue", "black"))
g + facet_grid(~ country)