Skip to content

Commit

Permalink
added geom_link_line, resolves #129, thanks @TC-Hewitt
Browse files Browse the repository at this point in the history
  • Loading branch information
thackl committed Oct 15, 2023
1 parent 057af6e commit 7a0b738
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 26 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export(geom_gene_note)
export(geom_gene_tag)
export(geom_gene_text)
export(geom_link)
export(geom_link_line)
export(geom_seq)
export(geom_seq_break)
export(geom_seq_label)
Expand Down
49 changes: 39 additions & 10 deletions R/geom_link.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#' Draw links
#' Draw links between genomes
#'
#' @description
#' `geom_link()` allows the user to link loci/regions between two sequences/genomes with one another.
#' @description Draws connections between genomes, such as genome/gene/protein
#' alignments and gene/protein clusters. `geom_link()` draws links as filled
#' polygons, `geom_link_line()` draws a single connecting line.
#'
#' *Note that by default only links between adjacent sequences are computed and shown.*
#' *To compute and show all links between all genomes, set `gggenomes(..., adjacent_only=FALSE)`.*
#' Note that by default only links between adjacent genomes are computed and
#' shown. To compute and show all links between all genomes, set
#' `gggenomes(..., adjacent_only=FALSE)`.
#'
#' @details
#' The function calls upon the data stored within the `link` track. Data frames added to
#' this track have `seq_id` and `seq_id2` as required variables. Optional and recommended variables include
#' `start`, `start2`, `end`, `end2`, `bin_id`, `bin_id2` and `strand`.
#' @details The function calls upon the data stored within the `link` track.
#' Data frames added to this track have `seq_id` and `seq_id2` as required
#' variables. Optional and recommended variables include `start`, `start2`,
#' `end`, `end2`, `bin_id`, `bin_id2` and `strand`.
#'
#' Note, when start/end is not specified, links will be created between the
#' entire contigs of `seq_id` and `seq_id2`.
#'
#' *Keep in mind: when start/end is not specified, links will be created between the entire contigs of `seq_id` and `seq_id2`*
#' @param offset distance between seq center and link start. Use two values
#' `c(<offset_top>, <offset_bottom>)` for different top and bottom offsets
#' @export
Expand Down Expand Up @@ -50,7 +54,32 @@ geom_link <- function(mapping = NULL, data = links(), stat = "identity",
params = list(na.rm = na.rm, offset = offset, ...)
)
}
#' @rdname geom_link
#' @export
#' @examples
#' q0 <- gggenomes(emale_genes, emale_seqs) |>
#' add_clusters(emale_cogs) +
#' geom_seq() + geom_gene()
#'
#' # link gene clusters with polygon
#' q1 <- q0 + geom_link(aes(fill=cluster_id))
#'
#' # link gene clusters with lines
#' q2 <- q0 + geom_link_line(aes(color=cluster_id))
#'
#' q1 + q2 + plot_layout(nrow=1, guides = "collect")
#'
#'
geom_link_line <- function(mapping = NULL, data = links(), stat = "identity",
position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
...){
default_aes <- aes(y=y, yend=yend, x=(x+xend)/2, xend=(xmin+xmax)/2)
mapping <- aes_intersect(mapping, default_aes)

layer(geom = GeomSegment, mapping = mapping, data = data, stat = stat,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...))
}

GeomLink <- ggproto(
"GeomLink", Geom,
Expand Down
70 changes: 54 additions & 16 deletions man/geom_link.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a0b738

Please sign in to comment.