Here is a reproducible example:
I first create a function based on this example https://github.com/hadley/ggplot2/wiki/labeller then provide the data and a graph
label_wrap_gen <- function(width = 100) {
function(variable, value) {
lapply(strwrap(as.character(value), width=width, simplify=FALSE),
paste, collapse="\n")
}
}
Data <- data.frame(Language=c("C++","C++","C++", "Java","Java","Java","Java", "PythonhasaREALLYWAYTOOlonglabel"),
Files=c(400, 210, 35,55,330,220,213,76),
Difficulty=c("a","b","c","d","e","f","g","h"),
stringsAsFactors=FALSE)
g <- ggplot(Data,aes(x=Difficulty,y=Files,fill=Difficulty)) #replaced fill=feetype,
h <- g + geom_bar(stat="identity",position="dodge") + facet_grid(.~ Language, scales = "free_x", space="free",labeller=label_wrap_gen(width=.1))
h
which produces a ggplot graph with a label for "PythonhasaREALLYWAYTOOlonglabel" that will oftentimes run off the edge of the plot.
I've tried playing with the various geom_bar
widths from the following link but too no avail:
How to increase the space between the bars in a bar plot in ggplot2?
Any help here? Thanks so much.