|
1 | 1 | #' Plot Antibody Data with Optional Antigen-Level Table or Time-Series Trend |
2 | 2 | #' |
3 | | -#' This function generates a bar plot of SAB (Single Antigen Beads) or PRA (Panel-Reactive Antibody) results |
4 | | -#' from a provided data frame or a file path. It can also plot MFI values over time. |
| 3 | +#' This function generates a bar plot of SAB (Single Antigen Beads) or PRA |
| 4 | +#' (Panel-Reactive Antibody) results from a provided data frame or a file path. |
| 5 | +#' It can also plot MFI values over time. |
5 | 6 | #' |
6 | | -#' @param result_file A data frame, a list of data frames (for trend plot), or a character string |
7 | | -#' specifying the path to a file in CSV, XLS, or XLSX format. |
8 | | -#' @param type Character. The type of assay, either "SAB" or "PRA". Defaults to "SAB". |
9 | | -#' @param class Character. For PRA plots, the class of the assay, either "I" or "II". Defaults to "I". |
10 | | -#' @param plot_trend Logical. If TRUE, a time-series plot is generated. Defaults to FALSE. |
| 7 | +#' @param result_file A data frame, a list of data frames (for trend plot), or |
| 8 | +#' a character string specifying the path to a file in CSV, XLS, or XLSX format. |
| 9 | +#' @param type Character. The type of assay, either "SAB" or "PRA". Defaults to |
| 10 | +#' "SAB". |
| 11 | +#' @param class Character. For PRA plots, the class of the assay, either "I" or |
| 12 | +#' "II". Defaults to "I". |
| 13 | +#' @param plot_trend Logical. If TRUE, a time-series plot is generated. Defaults |
| 14 | +#' to FALSE. |
11 | 15 | #' @param bead_cutoffs Numeric vector. Cutoff values for categorizing MFI values. |
12 | | -#' Defaults to `c(2000, 1000, 500, 250)` for SAB and `c(1500, 1000, 500, 250)` for PRA. |
13 | | -#' @param highlight_threshold Numeric. MFI threshold for highlighting alleles in the trend plot. Defaults to 2000. |
14 | | -#' @param vline_dates Vector of dates. Dates to draw vertical lines on the trend plot. |
| 16 | +#' Defaults to `c(2000, 1000, 500, 250)` for SAB and `c(1500, 1000, 500, 250)` |
| 17 | +#' for PRA. |
| 18 | +#' @param highlight_threshold Numeric. MFI threshold for highlighting alleles in |
| 19 | +#' the trend plot. Defaults to 2000. |
| 20 | +#' @param vline_dates Vector of dates. Dates to draw vertical lines on the trend |
| 21 | +#' plot. |
15 | 22 | #' @param add_table Logical. Whether to add the antigen-level information as a |
16 | | -#' table to the bottom of the bar plot. Defaults to TRUE. |
17 | | -#' @param x_text_angle Numeric. Angle for the antigen/allele text in the table. Defaults to 90. |
| 23 | +#' table to the bottom of the bar plot. Defaults to TRUE. |
| 24 | +#' @param x_text_angle Numeric. Angle for the antigen/allele text in the table. |
| 25 | +#' Defaults to 90. |
18 | 26 | #' @param palette Character. A color palette name. Defaults to "spectral". |
19 | 27 | #' @param highlight_antigen Character vector. Optional antigen(s) to highlight. |
20 | 28 | #' @param ... Additional arguments passed to the ggplot theme. |
21 | 29 | #' |
22 | 30 | #' @return A `ggplot` object. |
23 | 31 | #' |
24 | | -#' @importFrom ggplot2 ggplot aes geom_bar scale_fill_manual ylab guides theme element_blank geom_tile geom_text scale_y_discrete scale_color_manual scale_size labs geom_vline geom_line |
| 32 | +#' @importFrom ggplot2 ggplot aes geom_bar scale_fill_manual ylab guides theme |
| 33 | +#' element_blank geom_tile geom_text scale_y_discrete scale_color_manual |
| 34 | +#' scale_size labs geom_vline geom_line |
25 | 35 | #' @importFrom patchwork plot_layout |
26 | 36 | #' @export |
27 | 37 | plotAntibodies <- function(result_file, |
@@ -56,8 +66,9 @@ plotAntibodies <- function(result_file, |
56 | 66 |
|
57 | 67 | assay_long[, highlight := ifelse(allele %in% alleles_to_highlight, allele, "Other")] |
58 | 68 | assay_long[, sample := factor(sample, levels = unique(sample))] |
| 69 | + assay_long[, uniqueID := paste(allele, BeadID)] |
59 | 70 |
|
60 | | - p <- ggplot(assay_long, aes(x = sample_date, y = NormalValue, group = allele, color = highlight)) + |
| 71 | + p <- ggplot(assay_long, aes(x = sample_date, y = NormalValue, group = uniqueID, color = highlight)) + |
61 | 72 | geom_line(alpha = 0.7) + |
62 | 73 | scale_color_manual(values = c("Other" = "gray", setNames(.colorizer(n = length(alleles_to_highlight)), alleles_to_highlight))) + |
63 | 74 | .themeMatchR(...) + |
|
0 commit comments