2020# ' @param datasources a list of \code{\link[DSI]{DSConnection-class}} (default \code{NULL}) objects obtained after login
2121# '
2222# ' @return \code{ggplot} object
23+ # ' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2324
2425ds.boxPlotGG <- function (x , group = NULL , group2 = NULL , xlabel = " x axis" , ylabel = " y axis" , type = " pooled" , datasources = NULL ){
2526 x_var <- lower <- upper <- ymin <- ymax <- middle <- fill <- NULL
26- if (is.null(datasources )) {
27- datasources <- DSI :: datashield.connections_find()
28- }
29-
30- # ensure datasources is a list of DSConnection-class
31- if (! (is.list(datasources ) && all(unlist(lapply(datasources , function (d ) {methods :: is(d ," DSConnection" )}))))){
32- stop(" The 'datasources' were expected to be a list of DSConnection-class objects" , call. = FALSE )
33- }
27+ datasources <- .set_datasources(datasources )
3428
35- cally <- paste0(" boxPlotGGDS(" , x , " , " ,
36- if (is.null(group )){paste0(" NULL" )}else {paste0(" '" ,group ," '" )}, " , " ,
37- if (is.null(group2 )){paste0(" NULL" )}else {paste0(" '" ,group2 ," '" )}, " )" )
38-
39- pt <- DSI :: datashield.aggregate(datasources , as.symbol(cally ))
29+ plot_data <- datashield.aggregate(datasources , call(" boxPlotGGDS" , data_table.name = x , group = group , group2 = group2 ))
4030
4131 if (type == " pooled" ){
4232 num_servers <- length(names(datasources ))
43- pt_merged <- NULL
33+ plot_data_merged <- NULL
4434 for (i in 1 : num_servers ){
45- pt_merged <- rbind(pt_merged , pt [[i ]]$ data )
35+ plot_data_merged <- rbind(plot_data_merged , plot_data [[i ]]$ data )
4636 }
47- pt_merged <- data.table :: data.table(pt_merged )
37+ plot_data_merged <- data.table :: data.table(plot_data_merged )
4838 if (! is.null(group ) & is.null(group2 )){
49- pt_merged <- computeWeightedMeans(pt_merged ,
39+ plot_data_merged <- computeWeightedMeans(plot_data_merged ,
5040 variables = c(" ymin" , " lower" , " middle" , " upper" , " ymax" ),
5141 weight = " n" ,
5242 by = c(" group" , " x" ))
5343 }
5444 else if (! is.null(group ) & ! is.null(group2 )){
55- pt_merged <- computeWeightedMeans(pt_merged ,
45+ plot_data_merged <- computeWeightedMeans(plot_data_merged ,
5646 variables = c(" ymin" , " lower" , " middle" , " upper" , " ymax" ),
5747 weight = " n" ,
5848 by = c(" group" , " group2" , " x" ))
5949 }
6050 else {
61- pt_merged <- computeWeightedMeans(pt_merged ,
51+ plot_data_merged <- computeWeightedMeans(plot_data_merged ,
6252 variables = c(" ymin" , " lower" , " middle" , " upper" , " ymax" ),
6353 weight = " n" ,
6454 by = c(" x" ))
6555 }
66- if (pt [[1 ]][[length(pt [[1 ]])]] == " single_group" ){
67- plt <- ggplot2 :: ggplot(pt_merged ) +
56+ if (plot_data [[1 ]][[length(plot_data [[1 ]])]] == " single_group" ){
57+ plt <- ggplot2 :: ggplot(plot_data_merged ) +
6858 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
6959 upper = upper , ymin = ymin ,
7060 ymax = ymax , middle = middle ,
@@ -74,8 +64,8 @@ ds.boxPlotGG <- function(x, group = NULL, group2 = NULL, xlabel = "x axis", ylab
7464 ggplot2 :: ylab(ylabel ) +
7565 ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(angle = 90 , hjust = 1 ))
7666 }
77- else if (pt [[1 ]][[length(pt [[1 ]])]] == " double_group" ){
78- plt <- ggplot2 :: ggplot(pt_merged ) +
67+ else if (plot_data [[1 ]][[length(plot_data [[1 ]])]] == " double_group" ){
68+ plt <- ggplot2 :: ggplot(plot_data_merged ) +
7969 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
8070 upper = upper , ymin = ymin ,
8171 ymax = ymax , middle = middle ,
@@ -87,7 +77,7 @@ ds.boxPlotGG <- function(x, group = NULL, group2 = NULL, xlabel = "x axis", ylab
8777 ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(angle = 90 , hjust = 1 ))
8878 }
8979 else {
90- plt <- ggplot2 :: ggplot(pt_merged ) +
80+ plt <- ggplot2 :: ggplot(plot_data_merged ) +
9181 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
9282 upper = upper , ymin = ymin ,
9383 ymax = ymax , middle = middle )) +
@@ -102,8 +92,8 @@ ds.boxPlotGG <- function(x, group = NULL, group2 = NULL, xlabel = "x axis", ylab
10292 num_servers <- length(names(datasources ))
10393 plt <- NULL
10494 for (i in 1 : num_servers ){
105- if (pt [[i ]][[length(pt [[i ]])]] == " single_group" ){
106- plt [[i ]] <- ggplot2 :: ggplot(pt [[i ]][[1 ]]) +
95+ if (plot_data [[i ]][[length(plot_data [[i ]])]] == " single_group" ){
96+ plt [[i ]] <- ggplot2 :: ggplot(plot_data [[i ]][[1 ]]) +
10797 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
10898 upper = upper , ymin = ymin ,
10999 ymax = ymax , middle = middle ,
@@ -114,8 +104,8 @@ ds.boxPlotGG <- function(x, group = NULL, group2 = NULL, xlabel = "x axis", ylab
114104 ggplot2 :: ggtitle(paste0(" Server: " , names(datasources [i ]))) +
115105 ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(angle = 90 , hjust = 1 ))
116106 }
117- else if (pt [[i ]][[length(pt [[i ]])]] == " double_group" ){
118- plt [[i ]] <- ggplot2 :: ggplot(pt [[i ]][[1 ]]) +
107+ else if (plot_data [[i ]][[length(plot_data [[i ]])]] == " double_group" ){
108+ plt [[i ]] <- ggplot2 :: ggplot(plot_data [[i ]][[1 ]]) +
119109 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
120110 upper = upper , ymin = ymin ,
121111 ymax = ymax , middle = middle ,
@@ -128,7 +118,7 @@ ds.boxPlotGG <- function(x, group = NULL, group2 = NULL, xlabel = "x axis", ylab
128118 ggplot2 :: theme(axis.text.x = ggplot2 :: element_text(angle = 90 , hjust = 1 ))
129119 }
130120 else {
131- plt [[i ]] <- ggplot2 :: ggplot(pt [[i ]][[1 ]]) +
121+ plt [[i ]] <- ggplot2 :: ggplot(plot_data [[i ]][[1 ]]) +
132122 ggplot2 :: geom_boxplot(stat = " identity" , ggplot2 :: aes(x = x , lower = lower ,
133123 upper = upper , ymin = ymin ,
134124 ymax = ymax , middle = middle )) +
0 commit comments