使用网格时包裹小图表标题文本

时间:2019-01-26 02:47:16

标签: r ggplot2

示例说明:

library(tidyverse)

diamonds2 <- diamonds  

long_names <- c("very long label blah blah", "another long label look at that",
                "some text here big long label", "and so on and so forth", "the quick brown fox")

diamonds2$long <- long_names

ggplot(diamonds2, aes(x = depth, y = carat)) +
  geom_line() +
  facet_grid(cols = vars(long))

看起来像这样: enter image description here

我想包装每个Chartlet的标题,以便可以阅读所有文本。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

diamonds2$long <- long_names %>% str_wrap(width = 10)

...然后像以前一样进行ggplot:

enter image description here