[英]ggplot2: cannot override 2nd legend aesthetics when using stat_smooth
南瓜頭盔(3.1.2),ggplot2_1.0.0。
library(ggplot2)
some_diamonds <- subset(diamonds, color %in% c('D', 'E', 'F'))
g <- ggplot(some_diamonds, aes(carat, depth, linetype=cut, colour=color)) +
stat_smooth(se=F) + scale_colour_grey()
所需的顏色美感在color
的圖例中正確顯示(並且至關重要的是,在圖本身中),但是cut
的顏色默認為stat_smooth
的默認值(藍色)。 通常的技巧在這種情況下似乎不起作用,例如:
g <- ggplot(some_diamonds, aes(carat, depth, linetype=cut, colour=color)) +
stat_smooth(se=F)
g + scale_colour_grey() + guides(colour = guide_legend(override.aes =
list(colour='black')
實際上,我什至不知道如何訪問第二個圖例的任何元素。 這個
g + scale_colour_grey(guide=guide_legend(title="Title", order=2))
只需將第一個圖例的標題更改為“標題”; 同樣
g + scale_colour_grey() +
guides(colour=guide_legend(override.aes=list(colour='black'), order=2))
無論order
的值如何(甚至省略),都覆蓋cut
而不是color
。
我想念什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.