I've written a function to make graphs for a large dataset with hundreds of questions. All of the graphs are from the same dataset, and pull the title as a string from the 'graphtitle' column of a csv i've read in. Some of these titles are rather long and should be split to two lines. Perhaps because they're coming from the csv, the titles don't function with an \n
escape, and even if they did, it seems like there should be an easier way than adding \n
to each variable name in the appropriate place in the CSV.
Is there a way to make my function split the title lines automatically? I know I could change the size of the title, but that will render it largely illegible
MC.Graph <- function(variable){
p <- ggplot(data = newBEPS, aes_string(x=variable)) + geom_bar(aes(y = (..count..)/sum(..count..)), width = .5)+ scale_y_continuous(labels = percent)
p <- p + ggtitle(graphwords$graphtitle[graphwords$gw.varname == variable]) +
theme(plot.title = element_text(size =20, lineheight = .5, face = "bold"))
}