R ggplot2 center align a multi-line title -


if have title goes

... + ggtitle('something\nsomething else\nsomething else') 

is there way can each line center align rather left align in center?

...+ theme(plot.title=element_text(hjust=0.5)) 

gives me text in center, left aligned.

would work you,

# install.packages("ggplot2", dependencies = true) require(ggplot2)  df <- data.frame(x = rnorm(400)) m <- ggplot(df, aes(x = x)) + geom_histogram() m + labs(title = "vehicle \n weight-gas \n mileage relationship \n                   , long can seee it's centered") +       theme(plot.title = element_text(hjust = 0.5)) 

enter image description here

sorry typos in plot title …


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -