通过数组中的组合调用的动态交互图

时间:2018-11-12 16:41:19

标签: r

我有这个功能:

dynamic_plot_1 <- function(x1, x2) {

    Temp <- Data %>%
    group_by(Var1 = !!ensym(x1), Var2 = !!ensym(x2)) %>%
    summarise(
          number_of_samples = n()
          , median = median(bla)
    )

    Temp %>%
        ggplot() +
        aes(x = Var2, y = median, color = Var1) +
        geom_line(aes(group = Var1), size = 1) +
        geom_point() +
        geom_text(aes(label = paste0('£', median, ', samples:', number_of_samples)), hjust = 0, vjust = 0, color = 'black') +
        labs(x = x2, color = x1, y = 'bla')
} 

当我像这样调用它时效果很好:

dynamic_plot_1('x1', 'x2')

但是当我这样做时不是:

columns <- c(
  'x1'
, 'x2'
)
combination_matrix <- combn(columns, 2)

for (col in 1:ncol(combination_matrix)) {
    x1 <- quote(combination_matrix[1, col])
    x2 <- quote(combination_matrix[2, col])
    dynamic_plot_1(x1, x2)
}

有什么主意吗?谢谢!

0 个答案:

没有答案