When using geom_label for my (gg)plots in R, I notice that there is too much space above the text than there is below. How do I align the text to be in middle of the label box?
x <- data.frame(x = c("Being not", "Creative"), y = c(0.5, 1), text = c(543,12345))
g <- ggplot(data=x, aes(x, y)) + geom_bar(stat = 'identity', fill=c("red4","cornflowerblue"))
g + geom_label(aes(y = -Inf, label = text), vjust = -2)
# increasing `label.padding` here to exaggerate the white space
g + geom_label(aes(y = -Inf, label = text), vjust = -2, label.padding = unit(1, "lines")

vnudgeg + geom_label(aes(y = .25, label = text), label.padding = unit(1, "lines"))

Better yet: pass a vector of y coordinates to the y aes to specify midpoints.
g + geom_label(aes(y = c(.25, .5) label = text), label.padding = unit(1, "lines"))

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