word-wrap - 如何在 ggplot 中为 facet_grid 标签包装文本

标签 word-wrap facet-grid

我一直在寻找如何换行文本。似乎应该有一种方法可以使用 labeller = label_wrap_gen(3) 但我不断收到错误消息:
--- 边距错误(vars,边距):未使用的参数(边距)

这是我的代码的一部分:

#simpson by protected status for domain FKNMS
ggplot(data = fk_strata_abun_diversity, aes(x = YEAR)) +
geom_point(aes(y = strata_simpson, color = "strata_simpson"),color = "blue") +
geom_line(aes(y = strata_simpson, color = "strata_simpson"), color = "blue") +
facet_grid(STRAT ~ protected_status, 
         labeller = labeller(.rows = strata_names, .cols = protected_status_names),
         label_wrap_gen(width = 2)) + #error: in margins(vars, margins) : unused argument (margins) ?? 
labs(x = "Year", y = "Effective Number of Species") +
ggtitle("Simpson Diveristy of Reef Fish in the Florida Keys by Strata") + 
theme(plot.title = element_text(hjust = 0.5, face = 'bold', size = 12)) +
scale_x_continuous(limits = c(1999, 2016), breaks = c(1999:2016)) +
scale_y_continuous(limits= c(0, 25), breaks = c(5,10,15,20,25))

预先感谢您的帮助

最佳答案

我找到了 labeller = labeller(label_wrap_gen(width = 2 ...不包装。

尝试

facet_grid(STRAT ~ protected_status,
     labeller = label_wrap_gen(width = 2, multi_line = TRUE))

关于word-wrap - 如何在 ggplot 中为 facet_grid 标签包装文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796409/

相关文章:

css - 控制换行符使线条宽度相等

html - 如何在 Flexbox 布局中实现列表元素的自动换行

YAML 多行换行,不带空格

r - facet_grid中的免费色标

r - 使用 facet_grid 时,我可以为 x 和 y 以外的美学设置自由比例(例如尺寸)吗?

r - R 中 facet_grid() 的 labeller() 函数内的 tidy_eval

R:facet_wrap 无法在 Shiny 应用程序中使用 ggplotly 正确呈现

ios - 如何让文字环绕图像

python - Seaborn FacetGrid PointPlot 标签数据点

wpf - 减少 TextBlock/FlowDocument 中的行距