Closed TC-Hewitt closed 1 year ago
I have figured out a hacky solution in the meantime using trace to temporarily modify the geom_link function by changing the line
default_aes <- aes(y = y, x = x, xend = xend, yend = yend, xmin = xmin, xmax = xmax)
to
default_aes <- aes(y = y, x = x, xend = x, yend = yend, xmin = xmax, xmax = xmax)
then specifying linetype, offset and color with the function itself
geom_link(linetype=3, color="black", offset=0.1)
seems ok but not ideal as the lines are not centered to the middle of the genes. Please let me know if there is a better alternative? Thank you
Hi,
interesting question. You can use base ggplot::geom_segment
to draw just lines between genes:
library(gggenomes)
p1 <- gggenomes(emale_genes, emale_seqs) |> add_clusters(emale_cogs) +
geom_seq() + geom_gene()
# classic polygon links
p1 + geom_link()
# line link with use standard ggplot geom_segment
# need to explicitly set aes() and data=links() here!
# x/xend: link start/end on seq1
# xmin/xmax: link start/end on seq2
p1 + geom_segment(aes(y=y, yend=yend, x=(x+xend)/2, xend=(xmin+xmax)/2), data=links())
Hope that helps! Thomas
Or even a bit more elegantly by defining a new geom_link_line
function based on geom_segment
.
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 <- gggenomes:::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, ...))
}
p1 + geom_link_line(aes(color=cluster_id))
Thanks for this great answer. Does exactly what I was looking for and makes the plots much easier to interpret. The geom_link_line function is very convenient. Many thanks!
Hello, this is a great package. I'm plotting something like below (ignore the messy labels and colors): which was generated something like so:
The genes are automatically linked and colored by cluster as intended. However, is there a way to make the links appear as single connecting lines instead of adopting the thickness of the genes? For larger plots it gets quite messy. Ideally I just want a black, dashed line connecting each orthologous gene. Thank you