I am generating a figure that will be used as a column of labels to the right of a three-panel figure, and I would like the title of the figure to right-align as do the labels in the figure itself.
here is a minimal example in which I would like to right-align the title 'words'.
ggplot() +
geom_text(aes(y = 1, x = seq(4),
label = c('fee', 'fi', 'fo', 'fum'),
hjust = 1)) +
opts(title = 'words') +
coord_flip() +
scale_y_continuous(breaks = c(0,0), limits = c(0,1))
Which produces this:
update
The answer by @joran is helpful, but it does not align the words with the labels. changing his code from hjust=1
to hjust = 0.96
gets close, but this is more of a hack than a satisfying answer.
To change the size of the title and subtitle, we add the theme() function to labs() or ggtitle() function, whatever you used. Here we use labs() function. Inside theme() function, we use plot. title parameter for doing changes in the title of plot and plot.
You can do that with the following:
opts(plot.title = theme_text(hjust=1))
More generally, here is a reasonably complete list of things that can be altered via opts
and you can see some example code running through some of these options at Hadley's site here, particularly the section on 'polishing'. Even better would be to buy his book.
Note: Since version 0.9.2 opts
has been replaced by theme
:
theme(plot.title = element_text(hjust = 1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With