使用代码,我绘制了一个组合图:
library(ggplot2)
library(tidyverse)
library(patchwork)
library(glue)
library(cowplot)
small <- mtcars %>%
filter(carb %in% c(1, 2))
p1 <- qplot(mpg, wt, data = small, colour = cyl)
p2 <- qplot(mpg, data = small) + ggtitle("small")
p <- p1 | p2
n1 = 3
s1 = 'Zinc, Nickel, Silver'
n2 = 2
s2 = 'Copper, Aluminum'
text <- glue("The top {n1} commodities that price rose most are: {s1}; \\
the top {n2} commodities that fell most are: {s2}.")
title <- ggdraw() +
draw_label(text, size=12)
plot_grid(title, p, ncol=1, rel_heights=c(0.1, 1))
出去:
现在的问题是顶部的解释文本无法自适应地开始换行以显示所有内容?假设文本是一个长段落,它将超出情节界限。
我该如何解决这个问题?感谢您的评论和提前帮助。