Git Product home page Git Product logo

Comments (4)

TC-Hewitt avatar TC-Hewitt commented on June 24, 2024

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

from gggenomes.

thackl avatar thackl commented on June 24, 2024

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()

image

# 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())

image

Hope that helps!
Thomas

from gggenomes.

thackl avatar thackl commented on June 24, 2024

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))

from gggenomes.

TC-Hewitt avatar TC-Hewitt commented on June 24, 2024

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!

from gggenomes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.