i am using gglot with facet_wrap to plot some data. The dimensions within the different facets are very different (0.2 vs. 2000).
I plot geom_bar and add geom_text with the same values above the bar. Now there is a problem. The geom_text value is for "big" bars under the headline.
I see two possible solutions, both i can not implement.
Switch the geom_text position for big bars to plot inside. This could be done with vjust in the aes. But for every facet the switching point must be different.
I would like to scale the y-axis to 110%, so there is space for the text. But i do not want to put it manually to my program, because the plot is done automaticaly.
library(ggplot2)
testdata <- data.frame(a = c(0.1,0.2,0.3, 4,5,6, 7000,8000,9000),
b = c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c' ),
c = c('aa', 'bb', 'cc', 'aa', 'bb', 'cc', 'aa', 'bb', 'cc'))
ggplot(testdata, aes(x = c, y = a)) +
geom_bar(stat = 'identity') +
geom_text(aes(label = a), vjust = -1) +
facet_wrap(~b, ncol=1, scales = 'free_y')