我经常遇到必须调整输出图像大小的情况。不幸的是,这意味着通常我必须调整字体大小,以使内容可读。
例如,如果下面的图
library(ggplot2)
library(tibble)
library(stringi)
set.seed(1)
df <- tibble(
x = stri_rand_strings(10, 20),
y = runif(10) * 10,
label = stri_rand_strings(10, 10)
)
p <- ggplot(df, aes(x, y)) +
geom_text(aes(label = label)) +
scale_x_discrete(position = "top") +
theme(axis.text.x = element_text(angle = 90, hjust = 0))
保存为 12'' x 6'' 图像,看起来不错:
p + ggsave("test_small.png", width = 12, height = 6, unit = "in")
12'' x 6'' 输出 https://i.stack.imgur.com/FG8Qk.png
但是,如果我将尺寸增加到 36'' x 18'' 字体将无法阅读:
p + ggsave("test_large.png", width = 36, height = 18, unit = "in")
36 英寸 x 18 英寸 https://i.stack.imgur.com/nsGMR.png
是否有任何通用策略允许我们更改输出分辨率而无需不断修改字体大小?