thackl / gggenomes

A grammar of graphics for comparative genomics
https://thackl.github.io/gggenomes/
Other
572 stars 64 forks source link

Bézier curve for synteny block #104

Open baozg opened 2 years ago

baozg commented 2 years ago

Hi, @thackl

Can gggenomes use the Bézier curve for synteny block ? Like the sankey plot https://github.com/davidsjoberg/ggsankey image

thackl commented 2 years ago

No, not at the moment. But it's something that I also think would be nice to have. Not sure though, if I'll have the time to implement it...

thackl commented 2 years ago

Note to self: could probably use ggsankey::sigmoid() function to "smooth" geom_link() polygons.

sigmoid <- function(x_from, x_to, y_from, y_to, smooth = 5, n = 300) {
  x <- seq(-smooth, smooth, length = n)
  y <- exp(x) / (exp(x) + 1)
  out <- data.frame(x = (x + smooth) / (smooth * 2) * (x_to - x_from) + x_from,
                    y = y * (y_to - y_from) + y_from)
  out
}

library(tidyverse)

x0 <- tibble(x=c(1,10), y=c(1,10))
x1 <- sigmoid(x0$x[1], x0$x[2], x0$y[1], x0$y[2], 5, 50)

ggplot() + 
  geom_line(aes(x,y), data=x0) +
  geom_line(aes(x,y), data=x1, color="red")

image