ggplot:将标题扩展到绘图边距之外

时间:2017-03-21 17:01:34

标签: r ggplot2

我有一些带有长标签和长标题的情节。我使用的是coord_flip(),因此标签边缘以外的空间很多。默认情况下,标题受限于绘图边距。

如何让标题延伸到绘图边距(左侧)以便它可以跨越整个宽度?这是一个例子:

ggplot(diamonds, aes(x = cut)) + 
  geom_bar() + 
  coord_flip() + 
  scale_x_discrete("Cut", 
                   labels = c("Fair" = "Fair and a very long extra thing",
                              "Good" = "Good  and a very long extra thing",
                              "Very Good" = "VG  and a very long extra thing", 
                              "Premium" = "P and a very long extra thing. A very long label, just because", 
                              "Ideal" = "I and a very long extra thing")) + 
  ggtitle("This is my very long title.  Long long title. Very long.  The Longest. We have the best long titles.")

My plot with long labels/title

1 个答案:

答案 0 :(得分:4)

也许试试这个:

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

将标题移到。