Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot geom_bar can I highlight a bar in different color if value is above a threshold

I use ggplot and geo_bar to produce a plot, results is this:

enter image description here

Code

# 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))

Question

Can I have code that colors all bars in which the value is above 1000.

thx

like image 707
Hugo Koopmans Avatar asked Oct 31 '25 05:10

Hugo Koopmans


1 Answers

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') )  
like image 109
jraab Avatar answered Nov 02 '25 17:11

jraab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!