提问人:user63230 提问时间:10/27/2023 更新时间:10/27/2023 访问量:34
在 cowplot::save_plot 中使用 base_height 自动为 stringr::str_wrap 分配宽度
automatically assign width for stringr::str_wrap using base_height in cowplot::save_plot
问:
我想自动分配值,以便文本适合绘图的宽度,当我知道我想在以下方面使用时:width
str_wrap
base_height
save_plot
library(ggplot2)
library(cowplot)
library(stringr)
caption_text <- c("this is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long caption text")
p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
geom_point() +
theme(axis.text = element_text(size = 12, face = "bold", colour = "black"),
axis.title = element_text(size = 16, face = "bold", colour = "black")) +
labs(x = "Length", y = "Width",
caption = str_wrap(caption_text, width = 120))
p
save_plot("figures/pic.png",
p,
base_height = 8
)
(文字与剧情宽度不符)
我希望能够做的是像这样自动化它:
my_base_height = 8
str_wrap_width = my_base_height*SOME_VALUE
p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
geom_point() +
theme(axis.text = element_text(size = 12, face = "bold", colour = "black"),
axis.title = element_text(size = 16, face = "bold", colour = "black")) +
labs(x = "Length", y = "Width",
caption = str_wrap(caption_text, str_wrap_width))
p
save_plot("figures/pic.png",
p,
base_height = my_base_height
)
但我不知道如何提取具有已知值(英寸)的绘图的宽度,以便将其提供给.cowplot
base_height
str_wrap
有什么想法吗? 谢谢
答: 暂无答案
上一个:R stringr 解析案例字母
下一个:在 R 中替换数据框中的特定值
评论
str_wrap_width = my_base_height * (2 * dev.size()[1])
2
theme_cowplot()
2
facet_wrap)
facet_wrap
rows
cols