r - How to align ggplot title with window rather than plot grid? -


in ggplot2 version 0.9 behaviour of alignment of plot title changed. whereas in v0.8.9 alignment relative plot window, in v0.9 alignment relative plotting grid.

now, whereas agree desirable behaviour, quite have long plot titles.

question: there way of aligning plot title plot window rather plot grid?

i'm looking solution automatic alignment of plot. in other words, manual alignment using hjust not work me (i run on hundreds of plots each project).

any solution used grid directly acceptable.


some sample code , plot: (notice how title gets truncated @ right of window).

dat <- data.frame(   text = c(     "it made me feel positive brand x",      "it clear , easy understand",     "i didn't al all"),   value=runif(3) ) library(ggplot2) ggplot(dat, aes(text, value)) +    geom_bar(stat="identity") +   coord_flip() +   opts(title="thinking ad you've seen, agree following statements? agree that...") +   theme_bw(16) 

enter image description here

in ggplot2 0.9 can change layout.

p <- ggplot(dat, aes(text, value)) +    geom_bar(stat="identity") +   coord_flip() +   opts(title="thinking ad you've seen,\ndo agree following statements?\ni agree that...") +   theme_bw(16)  gt <- ggplot_gtable(ggplot_build(p)) gt$layout[which(gt$layout$name == "title"), c("l", "r")] <- c(1, max(gt$layout$r)) grid::grid.draw(gt) 

perhaps, in future version, ggplot2 provide consistent interfaces tweaking layout.

enter image description here


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -