如何删除ggplot geom_bar图例的横杆?

sam*_*asa 4 r legend ggplot2

我一直在WEB上搜索删除下面ggplot条形图的图例中的横杆.但是,没有成功.你能帮我解决这个问题.请参阅下面的数据"temp"和我正在使用的代码.你能告诉我如何在酒吧使用模式吗?谢谢.

temp:
    type    var value
    A   k1  20
    A   l1  30
    B   k1  10
    B   l1  15

    ggplot(temp,aes(type, value)) + geom_bar(stat="identity", aes(group=var, fill=type, facets=var),colour="blue1", position="identity") + facet_grid(.~var) + theme_bw()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

jor*_*ran 7

我知道这样做的唯一方法是做geom_bar两层,一层用蓝色,但没有图例,一层没有蓝色,但有一个图例:

ggplot(temp,aes(type, value)) + 
    geom_bar(stat="identity", aes(group=var, fill=type, facets=var),color = "blue1", position="identity",legend = "none") +
    geom_bar(stat="identity", aes(group=var, fill=type, facets=var), position="identity") +
    facet_grid(.~var) + 
    theme_bw()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

推测一点,我怀疑这不容易的原因是作为一个设计决策,包作者希望传说能够完全匹配图层中的内容.大多数时候,你可能对这种行为感到非常高兴,但偶然的尴尬带来了极大的便利.

  • @kkp No.请参阅[这里](http://stackoverflow.com/q/7604785/324364)以及Greg Snow的非常有趣的评论[这里](https://groups.google.com/forum/?fromgroups=# !searchin/ggplot2/geom_bar $ 20pattern/ggplot2/62T0RYtWz38/LVJYXx5QgTQJ)解释了这种阴影的历史,以及大多数人不再这样做的原因. (3认同)