ggplot2 draws two legends

后端 未结 1 918
暗喜
暗喜 2020-12-09 06:45

I have almost complete the following graph, but there is one problem with it.

The legend in the graph is drawn twice.

Here is the data:

str         


        
1条回答
  •  萌比男神i
    2020-12-09 07:43

    You have three aesthetics that are mapped to Variable: shape, colour, and linetype. Legends are collapsed together when they have the same title and labels. You have set the title to blank for colour and given it custom labels ("Significant Z-Score" and "Moran's I Z-Score"). You need to do that for linetype and shape as well to get them to collapse all together.

    Change

    scale_linetype_manual(values=c(1,3)) +
    

    to

    scale_linetype_manual(values=c(1,3), name="", labels=c("Signficant Z-Score",   "Moran's I Z-Score")) +
    

    and add

    scale_shape_discrete(name="", label=c("Signficant Z-Score", "Moran's I Z-Score")) +
    

    (You can also get rid of the scale_fill_discrete because you don't actually use the fill aesthetic anywhere.)

    This gives enter image description here

    0 讨论(0)
提交回复
热议问题