Skip to content

Commit 5ae5775

Browse files
committed
Update validation function to new endpoint types
1 parent 0cfc931 commit 5ae5775

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

R/aaa.R

+1
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ utils::globalVariables("TOTAL")
5252
utils::globalVariables("WIN_A")
5353
utils::globalVariables("WIN_P")
5454
utils::globalVariables("TIE_A")
55+
utils::globalVariables("linetype")

R/internal.R

+66-1
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,75 @@
692692
return(tte_data)
693693
}
694694

695+
.create_validation_binary_step <- function(layers, x, arms) {
696+
697+
binary_layers <- which(layers == "GeomSegment")
698+
699+
if (length(binary_layers) != 0) {
700+
binary_step_data <-
701+
do.call("rbind",
702+
lapply(binary_layers,
703+
function(i) {
704+
dat <- ggplot2::layer_data(plot = x,
705+
i = i)[, c("x", "y",
706+
"yend",
707+
"group",
708+
"linetype")]
709+
return(dat)
710+
}))
711+
712+
binary_step_data <- binary_step_data %>%
713+
dplyr::filter(linetype == 2) %>%
714+
dplyr::mutate(proportion = yend - y) %>%
715+
dplyr::select(x, y, proportion, group)
716+
717+
binary_step_data$group <- factor(binary_step_data$group, labels = arms)
718+
719+
} else {
720+
binary_step_data <- NULL
721+
}
722+
723+
return(binary_step_data)
724+
}
725+
726+
.create_validation_binary_last <- function(layers, x, arms) {
727+
728+
polygon_layers <- which(layers == "GeomPolygon")
729+
point_layers <- which(layers == "GeomPoint")
730+
731+
if (length(polygon_layers) == 1 &&
732+
length(point_layers) == 1) {
733+
734+
point_data <- ggplot2::layer_data(x, point_layers) %>%
735+
dplyr::select(x, y, group)
736+
737+
polygon_data <- unique(ggplot2::layer_data(x, polygon_layers))
738+
polygon_data <- polygon_data %>%
739+
dplyr::filter(y %in% point_data$y) %>%
740+
dplyr::group_by(group) %>%
741+
dplyr::summarise("lower_se" = base::min(x, na.rm = TRUE),
742+
"upper_se" = base::max(x, na.rm = TRUE))
743+
744+
binary_data <- dplyr::left_join(point_data, polygon_data,
745+
by = "group")
746+
binary_data$se <- binary_data$x - binary_data$lower_se
747+
binary_data$group <- factor(binary_data$group, labels = arms)
748+
749+
} else {
750+
751+
binary_data <- NULL
752+
753+
}
754+
755+
return(binary_data)
756+
}
757+
758+
759+
695760
.create_validation_scatter <- function(layers, x, arms) {
696761
scatter_data <- do.call("rbind", lapply(which(layers == "GeomPoint"),
697762
ggplot2::layer_data, plot = x))
698-
if (!is.null(scatter_data)) {
763+
if (!is.null(scatter_data) && nrow(scatter_data) > 2) {
699764
scatter_data <- scatter_data[, c("group", "x", "y")]
700765
scatter_data$group <- factor(scatter_data$group, labels = arms)
701766
}

R/maraca.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ plot_maraca <- function(
485485
) +
486486
ggplot2::geom_segment(
487487
data = tmp2,
488-
aes(x = x, y = y, xend = x, yend = yend),
488+
aes(x = x, y = y, xend = x, yend = yend,
489+
group = arm),
489490
color = "darkgrey", linetype = 2
490491
)
491492
}
@@ -662,6 +663,8 @@ validate_maraca_plot <- function(x, ...) {
662663
arms <- levels(pb$plot$data[, pb$plot$labels$colour])
663664

664665
tte_data <- .create_validation_tte(layers, x, arms)
666+
binary_step_data <- .create_validation_binary_step(layers, x, arms)
667+
binary_last_data <- .create_validation_binary_last(layers, x, arms)
665668
scatter_data <- .create_validation_scatter(layers, x, arms)
666669
boxstat_data <- .create_validation_box(layers, x, arms)
667670
violin_data <- .create_validation_violin(layers, x, arms)
@@ -685,6 +688,8 @@ validate_maraca_plot <- function(x, ...) {
685688
plot_type = plot_type,
686689
proportions = proportions,
687690
tte_data = tte_data,
691+
binary_step_data = binary_step_data,
692+
binary_last_data = binary_last_data,
688693
scatter_data = scatter_data,
689694
boxstat_data = boxstat_data,
690695
violin_data = violin_data,

tests/testthat/test_maraca.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,8 @@ test_that("validationFunction", {
940940
expect_type(val_res_scatter, "list")
941941

942942
expected_names <- c("plot_type", "proportions",
943-
"tte_data", "scatter_data",
943+
"tte_data", "binary_step_data",
944+
"binary_last_data", "scatter_data",
944945
"boxstat_data", "violin_data",
945946
"wo_stats")
946947
expect_named(val_res_def, expected_names, ignore.order = TRUE)

0 commit comments

Comments
 (0)