Is there a way to make good graphics of ā€œstreaming cardsā€ or ā€œline linesā€ in R?

I'm trying to find a way to recreate graphs like these directly in R (as opposed to manually drawing them with Inkscape after I did the analysis in R):

line flow 1 and line flow 2

The first seems to be straightforward, but I can't find anything that fits my needs ... the second is much more complicated, but it seems like it should be doable.

This post The state transition flowchart draws me closer to the end (this is already cool, except that I don’t necessarily have a square matrix, and I would like to indicate the start / end location for my lines with thickness control and alpha based my own data) ...

Can this be done with ggplot (or maybe something like a grid if it looks good)?

+8
r ggplot2 lattice gmisc
source share
1 answer

Here is an example to get started on the left graph using basic graphics (there are xspline functions for grid graphics, if you want to use them, I don’t know how to enable them with ggplot2, but the lattice is probably not too complicated):

plot.new() par(mar=c(0,0,0,0)+.1) plot.window(xlim=c(0,3), ylim=c(0,8)) xspline( c(1,1.25,1.75,2), c(7,7,4,4), s=1, lwd=32.8/4.5, border="#0000ff88", lend=1) xspline( c(1,1.25,1.75,2), c(6,6,4,4), s=1, lwd=19.7/4.5, border="#0000ff88", lend=1 ) xspline( c(1,1.25,1.75,2), c(5,5,4,4), s=1, lwd=16.5/4.5, border="#0000ff88", lend=1 ) xspline( c(1,1.25,1.75,2), c(4,4,4,4), s=1, lwd=13.8/4.5, border="#0000ff88", lend=1 ) xspline( c(1,1.25,1.75,2), c(3,3,4,4), s=1, lwd= 7.9/4.5, border="#0000ff88", lend=1 ) xspline( c(1,1.25,1.75,2), c(2,2,4,4), s=1, lwd= 4.8/4.5, border="#0000ff88", lend=1 ) xspline( c(1,1.25,1.75,2), c(1,1,4,4), s=1, lwd= 4.5/4.5, border="#0000ff88", lend=1 ) text( rep(0.75, 7), 7:1, LETTERS[1:7] ) text( 2.25, 4, 'Tie strength') 

enter image description here

And some initial code for the correct schedule using a slightly different approach:

 plot.new() par(mar=rep(0.1,4)) plot.window(xlim=c(0,7), ylim=c(-1,7)) text( 3+0.05, 0:6, 0:6, adj=0 ) text( 4-0.05, 0:6, 0:6, adj=1 ) lines( c(3,3),c(0-strheight("0"), 6+strheight("6")) ) lines( c(4,4),c(0-strheight("0"), 6+strheight("6")) ) xspline( c(3,1,3), c(0,3,6), s= -1, lwd=1, border="#00ff0055", lend=1 ) xspline( c(3,1.25,3), c(0,2.5,5), s= -1, lwd=4, border="#00ff0055", lend=1 ) xspline( c(4,4.5,4), c(5,5.5,6), s= -1, lwd=5, border="#ff000055", lend=1 ) 

enter image description here

You can change control points, colors, etc., to get closer to what you want. Then many parts could be wrapped in a function to automate part placement.

+11
source share

All Articles