How to use the raw string (such as len/s) in the colnames in ggpubr::ggboxplot
in R? It seems due to purrr::map
library(ggpubr)
data("ToothGrowth")
df <- ToothGrowth
colnames(df) <- c("len/s", "supp", "dose%sd")
ggboxplot(df, x = "dose%sd", y = 'len/s',
color = "dose%sd", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
add = "jitter", shape = "dose%sd")
with error
Error in `purrr::pmap()`:
ℹ In index: 1.
ℹ With name: len/s.
Caused by error in `purrr::map()`:
ℹ In index: 1.
ℹ With name: x.
Caused by error in `parse()`:
! <text>:1:5: unexpected input
1: dose%sd
---
Backtrace:
1. ggpubr::ggboxplot(...)
15. purrr::map(., function(x) parse_expression(x))
16. purrr:::map_("list", .x, .f, ..., .progress = .progress)
20. ggpubr (local) .f(.x[[i]], ...)
21. ggpubr:::parse_expression(x)
22. base::parse(text = x)
By default, the
parse_aes
option is set toTRUE
.We could set the
parse_aes
options toFALSE
and reset after the plotting-output
ggboxplot
callsggboxplot_core
internal function, which calls theggplot
withcreate_aes
whereparse = TRUE
The
create_aes.parse
calls theparse_expression
whereas thecreate_aes.name
converts to symbolTherefore, it is easier to set the
parse_aes
toFALSE