[英]Change color of geom_line in faceted plot
我希望每個國家/地區的線條與我手動設置的顏色相同。 即。 瑞典=紅色,美國=藍色,加拿大=綠色。
如何做到最好?
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.