如何在ggplot2中重命名(组合)图例?

时间:2015-06-12 15:15:57

标签: r ggplot2

是否可以重命名在ggplot2

中结合不同美学的图例

例如:

  1. 将颜色与线型相结合:Controlling line color and line type in ggplot legend
  2. 将颜色与形状相结合:How to recycle colours in a colorbrewer palette using line symbols
  3. 如何重命名这样的组合图例?当我尝试将name用于scale_shape_manualscale_color_manual时,组合的图例会分为两个不同的图例。那不是我想要的。

    可能的解决方案:我在这里找到的解决方案:https://stackoverflow.com/a/14622513/4317408为我工作......

    基本上有两种可能的方法,在两者中,组合图例获得一个新名称,两个不同图例中的name必须被修改为相同:

      scale_color_manual(values = c(brewer.pal(5, "Set1") ) , name = "Combined Legend Title") +
      scale_shape_manual(values = c(1,2,3,4,5) , name = "Combined Legend Title")
    

      guides(shape=guide_legend(title="Combined Legend Title"), color=guide_legend(title="Combined Legend Title"))
    

    我仍然想知道是否有更简单的方法可以做到这一点?

0 个答案:

没有答案