I would like to automatically wrap my labels in ggplot2, i.e. insert line breaks of long labels. Here is written how to write a function (1) for it, but sadly I do not know where to put labeller=label_wrap
in my code (2).
(1) function by hadley
label_wrap <- function(variable, value) {
lapply(strwrap(as.character(value), width=25, simplify=FALSE),
paste, collapse="\n")
}
(2) code example
df = data.frame(x = c("label", "long label", "very, very long label"),
y = c(10, 15, 20))
ggplot(df, aes(x, y)) + geom_bar(stat="identity")
I'd like to wrap some of the longer labels here.