5
ggplot(mpg, aes(displ, hwy)) +
      geom_point() +
      facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE))

I would like to replace the comma with space in labels.

Code output

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Zuooo
  • 337
  • 2
  • 11

2 Answers2

4

You can do something like this -

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

Note- We can pass any custom function by using this method.

Output-

Output

Rushabh Patel
  • 2,672
  • 13
  • 34
4
mpg$label <- paste(mpg$cyl, mpg$drv)

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

Final plots

Zuooo
  • 337
  • 2
  • 11