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.
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-
mpg$label <- paste(mpg$cyl, mpg$drv)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~label)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With