将图例中的ggplot彩色线条更改为正方形或圆形

Geo*_*tas 6 r ggplot2 legend-properties

而不是当前构成图例关键字的灰色背景上的彩色线条,我希望在关键标签旁边放置正方形或彩色圆圈,以便颜色易于看见.我怎样才能做到这一点?以下是一个用作示例的代码段:

 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")
Run Code Online (Sandbox Code Playgroud)

use*_*1_G 5

一个黑客来制作圆圈......

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)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明