【发布时间】:2021-02-02 14:21:16
【问题描述】:
我想使用ggplot 绘制条形图。当我定义所有参数时,ggplot 将根据数据框列名自动添加图例。这是我的数据框:
shift Var Ave
<dbl> <chr> <dbl>
1 0 Ave_los 268
2 0 Ave_los_n 195
3 1 Ave_los 284
4 1 Ave_los_n 217
5 2 Ave_los 214
6 2 Ave_los_n 194
这是我用来绘制的代码:
ggplot(data=data3, aes(x=shift, y=Ave, fill=Var)) +
geom_bar(stat="identity", position=position_dodge()) +
scale_x_continuous(breaks=c(0:2)) +
geom_text(aes(label=round(Ave,digit=2)), vjust=1.6, color="black", position = position_dodge(0.9), size=2.3)
这个绘图的结果如下所示:
但是,我不想使用 Ave_los 和 Ave_los_n 作为图例,而是想用 平均时间(积极组)替换它们 和 平均时间(否定组)。我该怎么做?
【问题讨论】:
-
@astrofunkswag 谢谢
标签: r ggplot2 bar-chart legend