Search code examples
rgrapharc-diagram

how to make an arc diagram of varying radius in R?


There are multiple R packages for arc diagram such as ggraph or arcdiagram, but if there're more than one connection of different nature, it will show as overlapping arcs of the same radius connecting the same origin and destination. Is it possible to have arc of different radius representing different categories? Something like in this rough graph? Thanks! enter image description here


Solution

  • We may use ggplot2 for that. Let the ending points be defined in df as

    library(ggplot2)
    df <- data.frame(x1 = 2, x2 = 3, y1 = 21, y2 = 15)
    

    Then we use geom_curve. It seems that we cannot use the curvature parameter as an aesthetic, but lapply allows to deal with that:

    ggplot(data = df, aes(x = x1, y = y1, xend = x2, yend = y2)) + 
      lapply(-5:5 / 10, function(cu) geom_curve(curvature = cu)) + theme_bw()
    

    enter image description here

    As to get multiple symmetric arcs I use various values of curvature defined as

    A numeric value giving the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves, and zero produces a straight line.