【问题标题】:How to remove the comma in facet labels when ".multi_line = FALSE"当“.multi_line = FALSE”时如何删除构面标签中的逗号
【发布时间】:2019-04-10 11:51:44
【问题描述】:
ggplot(mpg, aes(displ, hwy)) +
      geom_point() +
      facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE))

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

【问题讨论】:

    标签: r ggplot2 facet-wrap


    【解决方案1】:

    你可以这样做 -

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

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

    输出-

    【讨论】:

    • 我很高兴它有帮助!
    【解决方案2】:
    mpg$label <- paste(mpg$cyl, mpg$drv)
    
    ggplot(mpg, aes(displ, hwy)) +
          geom_point() +
          facet_wrap(~label)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-07
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多