Without adding an extra column to the data.frame, is there a built-in way to highlight the min/max bar? In the following example, I'd like the Joe bar to be green (max) and the John bar to be red (min).
I'm sure this has been asked before, but I couldn't find when searching:
data= data.frame( Name = c("Joe","Jane", "John") , Value = c(3,2,1) )
ggplot(data=data)+geom_bar(aes_string(x="Name",y="Value"), stat="identity" )
You can use subsetting:
p <- ggplot(data=data)+
geom_bar(aes(x=Name, y=Value), stat="identity") +
geom_bar(data=subset(data, Value==min(Value)), aes(Name, Value),
fill="red", stat="identity") +
geom_bar(data=subset(data, Value==max(Value)), aes(Name, Value),
fill="green", stat="identity")
print(p)

Here you go
ggplot(data, aes(Name, Value)) +
geom_bar(stat = 'identity') +
geom_bar(stat = 'identity', aes(fill = factor(Value)),
subset = .(Value %in% range(Value))) +
scale_fill_manual(values = c('red', 'green'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With