如何使用R中ggpubr::ggboxplot
的列名中的原始字符串(如len/s)?这似乎是由于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")
有误差
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)
1条答案
按热度按时间yhqotfr81#
默认情况下,
parse_aes
选项设置为TRUE
。我们可以将
parse_aes
选项设置为FALSE
,并在绘制后重置ggboxplot
调用ggboxplot_core
内部函数,该函数使用create_aes
调用ggplot
,其中parse = TRUE
create_aes.parse
调用parse_expression
,而create_aes.name
转换为符号因此,更容易将
parse_aes
设置为FALSE