开发者

Is it possible to align the title of a ggplot to the right?

开发者 https://www.devze.com 2023-03-16 01:37 出处:网络
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.

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:

Is it possible to align the title of a ggplot to the right?

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.


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)) 
0

精彩评论

暂无评论...
验证码 换一张
取 消