下面的代碼繪製了一個圖表,其中顏色的名稱以正確的順序出現在圖例中,但顏色本身以相反的順序出現。爲什麼?ggplot2:爲什麼geom_line()圖形的顏色順序顛倒了?
year <- 2000:2009
a1 <- 4 + rnorm(10)
a2 <- 3 + rnorm(10)
a3 <- 2 + rnorm(10)
a4 <- 0.25 * rnorm(10)
vv <- tibble(year, a1, a2, a3, a4)
test <- ggplot(data=vv) + aes(x=year) +
geom_line(aes(y = a1, colour= "blue")) +
geom_line(aes(y = a2, colour= "green")) +
geom_line(aes(y = a3, colour= "yellow")) +
geom_line(aes(y = a4, colour= "orange")) +
expand_limits(y=0)
test