为ggplot2中的每个图例分配不同的背景颜色

问题描述

page显示了如何使用ggplot函数来处理guide_legend的多个图例,例如顺序,标题颜色。我想知道是否可以单独修改每个图例的背景颜色。谢谢!

ggplot(mpg,aes(displ,cty)) +
  # I tired to use legend.background and a list of colors in fill to individually change the color,but is it not working
  theme(legend.background=element_rect(fill=c('brown','grey','whie'))) +
  geom_point(aes(size = hwy,colour = cyl,shape = drv)) +
  guides(
    colour = guide_colourbar(order = 1),# title.theme allows individual adjustment of title color,I wonder if similar can be done for legend background color
    shape = guide_legend(order = 2,title.theme = element_text(color='green')),size = guide_legend(order = 3,label.theme=element_text(color='red'))
  )

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)