2
我在使用geom_line()的圖的頂部繪製了一些線段。令人驚訝的是,geom_line()的指南(圖例)顏色被繪製爲我添加到圖的最後一個元素的顏色 - 即使它不是geom_line()。這對我來說看起來像一個bug,但是由於某種原因,我可能會預料到行爲我不明白。當geom_line()和geom_segment()一起使用時看似不正確的指導顏色
#Set up the data
require(ggplot2)
x <- rep(1:10, 2)
y <- c(1:10, 1:10+5)
fac <- gl(2, 10)
df <- data.frame(x=x, y=y, fac=fac)
#Draw the plot with geom_segment second, and the guide is the color of the segment
ggplot(df, aes(x=x, y=y, linetype=fac)) +
geom_line() +
geom_segment(aes(x=2, y=7, xend=7, yend=7), colour="red")
而如果我先加geom_segment,導板上的顏色是黑色,因爲我所期望的:
ggplot(df, aes(x=x, y=y, linetype=fac)) +
geom_segment(aes(x=2, y=7, xend=7, yend=7), colour="red") +
geom_line()
功能或者錯誤?如果第一個,有人可以解釋發生了什麼?
地址:',show_guide = FALSE'到'geom_segment' –
OK,但爲什麼它在引導顯示在所有?我期望geom_segment被認爲是數據的「外部」,所以它通常不會影響指南 - 如果它確實如此,那麼將它添加到圖表中的順序應該沒有關係。 –