I\'m trying to make a bar graph (with geom_bar) of ratios, and would like to set the x-axis at y=1. Therefore, ratios <1 would be below the axis and ratios >1 would be ab
We can do this with a custom transformation of the y-scale:
shift_trans = function(d = 0) {
scales::trans_new("shift", transform = function(x) x - d, inverse = function(x) x + d)
}
ggplot(dat, aes(x, ratio, fill = ifelse(ratio > 1,"GT1","LT1"))) +
geom_bar(stat="identity") +
scale_fill_manual(values=c("blue","red"), name="LT or GT 1") +
scale_y_continuous(trans = shift_trans(1))
This approach is nicely general and is parmaterized.
Using the data eipi10's answer: dat = data.frame(ratio=-4:11/3, x=1:16)