多个图例设置图例关键圈颜色

时间:2017-04-07 19:45:52

标签: r ggplot2

我有这个情节:

dates = c("2017-03-13","2017-03-13","2017-03-14","2017-03-14","2017-03-14")
value = c(5,6,7,8,9)
group = c("A","B","A","B","C")
size = c(10,20,30,40,50)
data =data.frame(dates= dates, value = value, group = group, size = size)
ggplot(data, aes(x = dates, y = value, group = group)) + geom_point(aes (color = as.factor(group), size= size ))+
 scale_color_manual(name="group",
                     labels = c(A="A",B= "B",C = "C"),
                     values = c(A="green",B="red" , C = "orange" )
  ) + theme(
    panel.background = element_rect(fill = "black", colour = "black"),
    legend.key = element_rect(colour = "black", fill = "black")
  )

有两个问题:

(1)目前在尺寸图例中,圆圈为黑色,背景为黑色。如何将圆圈的颜色设置为红色,以便在黑色背景上看到圆圈?

1 个答案:

答案 0 :(得分:2)

override.aes中需要guide_legend才能更改图例中的美学设置而不更改图表。

+ guides(size = guide_legend(override.aes = list(color = "red")))