我想创建一个条形图,其中包含基于activity
的躲避条形图和由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 bar根据填充美感闪避条纹,颜色美学只会改变边框颜色,例如。
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