|
692 | 692 | return(tte_data)
|
693 | 693 | }
|
694 | 694 |
|
| 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 | + |
695 | 760 | .create_validation_scatter <- function(layers, x, arms) {
|
696 | 761 | scatter_data <- do.call("rbind", lapply(which(layers == "GeomPoint"),
|
697 | 762 | ggplot2::layer_data, plot = x))
|
698 |
| - if (!is.null(scatter_data)) { |
| 763 | + if (!is.null(scatter_data) && nrow(scatter_data) > 2) { |
699 | 764 | scatter_data <- scatter_data[, c("group", "x", "y")]
|
700 | 765 | scatter_data$group <- factor(scatter_data$group, labels = arms)
|
701 | 766 | }
|
|
0 commit comments