ggplot legend slashes

前端 未结 2 1763
北荒
北荒 2020-12-16 12:21

This must have annoyed someone in the past so excuse me if this is a duplicate and I will remove it. Slashes across legends when using geom_bar can be annoying

相关标签:
2条回答
  • 2020-12-16 12:38

    this,

     a + geom_bar() + geom_bar(colour="black",show_guide=FALSE) +
     scale_fill_manual(values=c("white", "black")) + 
     opts(legend.key = theme_rect(fill = 'black'))
    

    gave me this, enter image description here thanks to this site.

    Alos, you get the same result using colour instead of fill (it might be argued that one is better than).

    a + geom_bar() + geom_bar(colour="black",show_guide=FALSE) + 
    scale_fill_manual(values=c("white", "black")) + 
    opts(legend.key = theme_rect(colour = 'black'))
    

    Important note: In modern versions of ggplot2 opts has been deprecated and replaced with theme, and theme_rect has been replaced by element_rect.

    0 讨论(0)
  • 2020-12-16 12:39

    No that's what gives it it's outline. If you use a gray instead of white (with your trick) it's more distinguishable. You could also add background color to the legend to make it more distinguishable and keep it white. See the bottom of this page for more detail:

    http://wiki.stdout.org/rcookbook/Graphs/Legends%20(ggplot2)/

    i wish there were a less hackish way to do this.

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