如何在“.multi_line = FALSE”中删除构面标签中的逗号

问题描述 投票:2回答:2
ggplot(mpg, aes(displ, hwy)) +
      geom_point() +
      facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE))

我想用标签中的空格替换逗号。

r ggplot2 facet-wrap
2个回答
3
投票

你可以这样做 -

 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))
    })

注意 - 我们可以使用此方法传递任何自定义函数。

输出 -

Output


3
投票
mpg$label <- paste(mpg$cyl, mpg$drv)

ggplot(mpg, aes(displ, hwy)) +
      geom_point() +
      facet_wrap(~label)

© www.soinside.com 2019 - 2024. All rights reserved.