Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 删除默认ggplot图例并创建自定义图例_R_Ggplot2_Bar Chart_Legend - Fatal编程技术网

R 删除默认ggplot图例并创建自定义图例

R 删除默认ggplot图例并创建自定义图例,r,ggplot2,bar-chart,legend,R,Ggplot2,Bar Chart,Legend,我想使用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

我想使用
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
该图的结果如下所示:


但是,我不想用平均时间(阳性组)平均时间(阴性组)来代替它们。如何执行此操作?

使用tidyverse中的重新编码更改列“Var”的值。对此作了全面的解释


@astrofunkswag谢谢
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)
library(tidyverse)
    data3%>%recode(Ave, Ave_los = "Average Time (positive group)", Ave_los_n = "Average Time (negative group")%>%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)