我有一个包含多个变量的数据框,我希望将其标记,然后在几个ggplots中使用。我使用labeller包使用以下代码应用标签。
库(tidyverse)图书馆(…
你可以给出名字 vars 然后使用其中之一 map2() 要么 imap() 功能来自 purrr 打包以循环它们。要包含上标/下标/数学符号,请使用 expression() 和...一起 parse(text = ...) (另见这些 例1 , 例题 )。
vars
map2()
imap()
purrr
expression()
parse(text = ...)
names(vars) <- c(expression('effect of Rx'^{1}), "response", expression(weight/individual %.% kg[2]) ) vars #> "effect of Rx"^{\n 1\n} response #> "v1" "v2" #> weight/individual %.% kg[2] #> "v3" ### from purrr package map2(vars, names(vars), ~ ggqqplot(example.df, x = .x, combine = FALSE, facet.by = "origin") + ggtitle(parse(text = .y))) # or `imap(x, ...)` which is short hand for map2(x, names(x), ...) imap(vars, ~ ggqqplot(example.df, x = .x, combine = FALSE, facet.by = "origin") + ggtitle(parse(text = .y))) #> $`"effect of Rx"^{\n 1\n}`
#> #> $response
#> #> $`weight/individual %.% kg[2]`
创建于2019-03-11由 代表包 (v0.2.1.9000)