4

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

Hugo Koopmans
  • 1,349
  • 1
  • 15
  • 27
  • 4
    You should include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with your question with sample data so we can run the same code as you to test possible answers. Have you tried setting a `color=` aesthetic at all? `geom_bar(aes(color=freq>1000), stat="identity")`? – MrFlick Jan 27 '15 at 19:40
  • 1
    You can embed an ifelse statement in aes(fill=) - that may do what you want. – jraab Jan 27 '15 at 19:47

1 Answers1

12
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') )  
jraab
  • 413
  • 4
  • 10