r - ggplot geom_bar 如果值高于阈值,我可以突出显示不同颜色的条吗

标签 r ggplot2 geom-bar

我使用 ggplot 和 geo_bar 来生成一个图,结果是这样的:

enter image description here

代码

# Faceting is a good alternative:
ggplot(df.cnts, aes(x=date,y=freq)) + geom_bar(stat="identity") +
  facet_wrap(~ operator, nrow = 3) +
  theme(axis.text.x  = element_text(angle=90, vjust=0.5, size=8))



我可以编写代码来为值大于 1000 的所有条形着色吗?

谢谢

最佳答案

mt_mean <-   mtcars %>% group_by(cyl) %>% summarise(avg_mpg = mean(mpg) )  

ggplot( mt_mean , aes(x=cyl, y =avg_mpg)) + 
    geom_bar(stat = 'identity', aes(fill = avg_mpg > 25 )  ) 

g + scale_fill_manual(values = c('red', 'black') )  

关于r - ggplot geom_bar 如果值高于阈值,我可以突出显示不同颜色的条吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28178495/

相关文章:

r - "Found the following calls to data() loading into the global environment"

按值对 geom_bar ggplot2 中的条形图重新排序

r - 如何将 R 中的数据框绘制为热图/网格?

R ggplot geom_bar 错误 : Discrete value supplied to continuous scale

r - ggplot2 (Barplot + LinePlot) - 双 Y 轴

删除两个图例中的线条和背景

r - 'closure' 类型的对象在 shiny 中不可子集化。使用简单的 RGL 绘图函数

r - 在 R 中查找观察值之间的时间差

r - 2 基于一个 Shiny 的小部件在 Rmarkdown 中并排绘制

r - 使用 ggplot2 网格显示不良