小编Ram*_*tes的帖子

如何使用purrr循环整理eval函数?

我有以下数据集(示例):

train <- data.frame(ps_ind_06_bin = c(FALSE, FALSE, FALSE, TRUE, TRUE, FALSE),
                        ps_ind_07_bin = c(FALSE, TRUE, TRUE, FALSE, TRUE, TRUE),
                        ps_ind_08_bin = c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE),
                        ps_ind_09_log = c(1, 3, 4, 2, 3, 2))
Run Code Online (Sandbox Code Playgroud)

我有以下函数显示group_by()操作的ggplot :

get_charts1 <- function(mygroup){
  quo_var <- enquo(mygroup)
  train %>% 
    group_by(!!quo_var) %>% 
    count() %>%
    ungroup() %>%
  ggplot(aes_q(x = quo_var, y = quote(n), fill = quo_var)) + 
    geom_col() +
    theme(legend.position = "none")
    }
Run Code Online (Sandbox Code Playgroud)

我手动输入列名称时工作正常,例如:

get_charts1(ps_ind_07_bin)
Run Code Online (Sandbox Code Playgroud)

但是,我想在几个列上使用该函数,我将它放在一个向量上:

binarias <- train %>% 
             select(ends_with("bin")) %>% 
             colnames()
Run Code Online (Sandbox Code Playgroud)

使用地图并提出一些建议,我试图使用: …

r ggplot2 purrr tidyverse tidyeval

10
推荐指数
2
解决办法
808
查看次数

标签 统计

ggplot2 ×1

purrr ×1

r ×1

tidyeval ×1

tidyverse ×1