[英]Adjusting geom_bar (position=“dodge”) in ggplot
[英]Geom_bar with position dodge on one categorical variable and colour on another
我想根据activity
和由thres
决定的条形颜色thres
或者根据条件选择条形颜色: cpue > 75 = 'green'
cpue < 75 & cpue > 50 = 'orange'
cpue < 50 = 'purple'
数据的示例是:
week area_code activity cpue p_legal thres thres2
<dbl> <chr> <chr> <dbl> <dbl> <chr> <chr>
1 30 2L12 Looking NaN NaN green green
2 31 2L12 Fishing 81.96667 90.00000 green green
3 31 2L12 Looking 61.32353 90.00000 orange green
4 32 2L12 Fishing 87.07883 80.00000 green green
5 32 2L12 Looking 66.99622 94.33333 orange green
6 35 2L12 Fishing 60.29923 86.25000 orange green
我知道我可以像这样使用多面包装:
ggplot(plot_df[plot_df$area_code == area, ]) +
geom_bar(aes(x=week, y=cpue, fill=thres), stat='identity') +
scale_fill_manual(values=c('green'= 'green', 'orange'='orange', 'purple' = 'purple'), guide=FALSE) +
geom_hline(yintercept = c(50, 75)) +
facet_wrap(~activity)
我实际上想要的是躲避条,但我遇到的问题是,geom条避开了基于填充美学的躲避条,而颜色美学仅更改了边框颜色,例如
ggplot(plot_df[plot_df$area_code == area, ]) +
geom_bar(aes(x=week, y=cpue, fill=activity, colour = thres), position = 'dodge', stat='identity') +
geom_hline(yintercept = c(50, 75))
我想要与上述相同的输出,但条形由所概述的条件或thres
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.