[英]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.