|
31 | 31 | #' @importFrom stats as.formula |
32 | 32 | #' @importFrom ggh4x facet_wrap2 strip_themed elem_list_rect |
33 | 33 | #' @importFrom dplyr group_by summarise |
34 | | -#' @importFrom dplyr %>% |
| 34 | +#' @importFrom dplyr %>% filter |
35 | 35 | #' @importFrom ggrepel geom_text_repel |
36 | 36 | #' @importFrom utils tail |
37 | 37 | #' |
@@ -336,34 +336,24 @@ geom_coverage <- function(data, mapping = NULL, color = NULL, rect.color = NA, |
336 | 336 | # add rect |
337 | 337 | if (!is.null(mark.region)) { |
338 | 338 | # get valid mark region |
339 | | - region.start <- data[1, "start"] |
340 | | - region.end <- data[nrow(data), "end"] |
341 | | - valid.region.list <- list() |
342 | | - for (r in 1:nrow(mark.region)) { |
343 | | - if (mark.region[r, "start"] <= region.end & mark.region[r, "end"] >= region.start) { |
344 | | - if (mark.region[r, "end"] >= region.end) { |
345 | | - mark.region[r, "end"] <- region.end |
346 | | - } |
347 | | - if (mark.region[r, "start"] <= region.start) { |
348 | | - mark.region[r, "start"] <- region.start |
349 | | - } |
350 | | - valid.region.list[[r]] <- mark.region[r, ] |
351 | | - } |
352 | | - } |
353 | | - valid.region.df <- do.call(rbind, valid.region.list) %>% as.data.frame() |
354 | | - colnames(valid.region.df) <- colnames(mark.region) |
355 | | - |
| 339 | + region.start <- min(data$start) |
| 340 | + region.end <- max(data$end) |
| 341 | + mark.region <- dplyr::filter( |
| 342 | + mark.region, |
| 343 | + .data[["start"]] >= region.start, |
| 344 | + .data[["end"]] <= region.end |
| 345 | + ) |
356 | 346 | region.mark <- geom_rect( |
357 | | - data = valid.region.df, |
| 347 | + data = mark.region, |
358 | 348 | aes_string(xmin = "start", xmax = "end", ymin = "-Inf", ymax = "Inf"), |
359 | 349 | fill = mark.color, alpha = mark.alpha |
360 | 350 | ) |
361 | 351 | plot.ele <- append(plot.ele, region.mark) |
362 | 352 | # add rect label |
363 | 353 | if (show.mark.label) { |
364 | | - if ("label" %in% colnames(valid.region.df)) { |
| 354 | + if ("label" %in% colnames(mark.region)) { |
365 | 355 | # create mark region label |
366 | | - region.label <- valid.region.df |
| 356 | + region.label <- mark.region |
367 | 357 | if (plot.type == "facet") { |
368 | 358 | region.label[, facet.key] <- facet.order[1] |
369 | 359 | } |
|
0 commit comments