Reputation: 2380
I want the lines for each country to be the same colour that I manually set. ie. Sweden = Red, USA = Blue, Canada = Green.
How best to do this?
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)
Upvotes: 0
Views: 2849
Reputation: 66415
EDIT: removed mapping distinguishing deciles.
g <- ggplot(df, aes(x = date, y = income, group = decile, color = country)) +
geom_line(size = 2) +
scale_color_manual(values = c("Sweden" = "red", "Canada" = "green",
"USA" = "blue")) +
facet_grid(~ country)
g
Upvotes: 2