“.multi_line = FALSE”时如何删除构面标签中的逗号
How to remove the comma in facet labels when ".multi_line = FALSE"
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE))
我想用 space 替换标签中的逗号。
你可以这样做 -
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(c("cyl", "drv"), labeller = function (labels) {
labels <- lapply(labels, as.character)
a <- do.call(paste, c(labels, list(sep = ",")))
list(gsub("\,"," ",a))
})
注意- 我们可以使用此方法传递任何自定义函数。
输出-
mpg$label <- paste(mpg$cyl, mpg$drv)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~label)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE))
我想用 space 替换标签中的逗号。
你可以这样做 -
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(c("cyl", "drv"), labeller = function (labels) {
labels <- lapply(labels, as.character)
a <- do.call(paste, c(labels, list(sep = ",")))
list(gsub("\,"," ",a))
})
注意- 我们可以使用此方法传递任何自定义函数。
输出-
mpg$label <- paste(mpg$cyl, mpg$drv)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~label)