Use dataframe variable names in plot titles

左心房为你撑大大i 提交于 2019-11-29 16:47:30

You can give the names to vars then use either map2() or imap() functions from the purrr package to cycle through them. To include superscripts/subscripts/math notation, use expression() together with parse(text = ...) (see also these example1, example2).

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]`

Created on 2019-03-11 by the reprex package (v0.2.1.9000)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!