代替当前构成图例键的灰色背景上的彩色线条,我希望在关键标签旁边放置方形或颜色圆圈,以便颜色易于看清。我怎样才能做到这一点?以下是一个用作示例的代码段:
mry <- do.call(rbind, by(movies, round(movies$rating), function(df) {
nums <- tapply(df$length, df$year, length)
data.frame(rating=round(df$rating[1]), year = as.numeric(names(nums)),
number=as.vector(nums))
}))
ggplot(mry, aes(x=year, y=number, colour=factor(rating))) + geom_line() +
scale_colour_brewer(palette="YlGnBu")
答案 0 :(得分:4)
一个黑客出现在圈子里......
ggplot(mry, aes(x=year, y=number, colour=factor(rating))) +
scale_colour_brewer(palette="YlGnBu") +
geom_point() +
geom_point(size=5,colour="white",show_guide=FALSE) +
opts(
panel.background = theme_rect(fill = "transparent"),
panel.grid.minor = theme_blank(),
panel.grid.major = theme_blank(),
plot.background = theme_rect(fill = "transparent",colour = NA)
) + geom_line(show_guide=FALSE)