我知道之前有很多关于构面标签的问题,但考虑到labeller
ggplot2
已更改label_both()
,我觉得这个问题是合理的。
我希望能够使用label_both(labels, multi_line = TRUE, sep = ": ")
labels: Data frame of labels. Usually contains only one element, but facetting over multiple
factors entails multiple label variables.
multi_line: Whether to display the labels of multiple factors on separate lines.
sep: String separating variables and values.
功能更改构面的标签。帮助文件说明:
label_both(labels = data.frame(AM = c("0", "1", "0", "1"), VS = c("0", "0", "1", "1")),
multi_line = F)
#> [[1]]
#> [1] "AM, VS: 0, 0" "AM, VS: 1, 0" "AM, VS: 0, 1" "AM, VS: 1, 1"
使用此信息,我可以定义自己的标签:
my_labels <- label_both(labels = data.frame(AM = c("0", "1", "0", "1"),
VS = c("0", "0", "1", "1")),
multi_line = F)
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
facet_grid(vs + am ~ gear, labeller = labeller(.rows = my_labels))
然而,当我尝试在情节中使用它时,它不起作用。
as_labeller()
我究竟做错了什么?我意识到我可以重新定义那个因子标签,但我真的很想知道为什么它不起作用。
编辑:一种解决方案是使用mylabels = as_labeller(c(`0` = "AM: Zero", `1` = "AM: One"))
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
facet_grid(vs + am ~ gear, labeller = labeller(am = mylabels, .multi_line = FALSE))
定义标签:
label_both()
但是这并没有使用created site1(2 & 3).com.conf and enabled them
答案 0 :(得分:1)
这有效,似乎是label_both
:
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
facet_grid(vs + am ~ gear, labeller = labeller(.rows = label_both, .multi_line = FALSE))