【发布时间】:2020-12-16 15:45:51
【问题描述】:
我正在尝试制作facet_grid 图,如下例所示。其中一个方面的名称太长而无法正确显示,因此被截断。
我尝试在文本周围添加边距以正确显示完整的方面名称。但是,element_text 中的 margin 选项只允许我添加水平边距 - 文本字段的高度似乎是固定的。有没有办法也可以添加垂直边距?
library (ggplot2)
x <- mtcars
x$cyl <- as.factor (x$cyl)
levels (x$cyl) <- c ("a", "b", "this is a very very long name")
ggplot (x, aes (x = mpg, disp)) +
geom_point () +
facet_grid (cyl ~ .) +
theme (strip.text = element_text (margin = margin (30, 5, 30, 5))) # This line should increase the margins
版本信息:R 4.0.3,ggplot2 3.3.2
【问题讨论】: