【问题标题】:Is there a way to make nice "flow maps" or "line area" graphs in R?有没有办法在 R 中制作漂亮的“流程图”或“线面积”图?
【发布时间】:2014-06-11 20:28:52
【问题描述】:

我正在尝试找到一种方法来直接在 R 中重新创建此类图形(而不是在我在 R 中完成分析后使用 Inkscape 手动绘制它们):

第一个看起来应该是直截了当的,但我找不到任何适合我需要的东西......第二个要复杂得多,但似乎也应该应该 可行。

这篇文章Graph flow chart of transition from states 让我非常接近(它已经有点棒了,除了我不一定有方阵,而且我想为我的线条指定一个开始/结束位置以控制粗细和基于我自己的数据的阿尔法)...

是否可以使用 ggplot(或者其他类似 lattice 的东西,如果它看起来不错)来做到这一点?

【问题讨论】:

标签: r ggplot2 lattice gmisc


【解决方案1】:

这是一个使用基本图形从左图开始的示例(如果您想使用网格图形也有 xspline 函数,我不知道如何将它们与 ggplot2 合并,但 lattice 可能会不要太难):

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

还有一些使用不同方法的正确图表的起始代码:

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 )

您可以修改控制点、颜色等,以更接近您想要的。然后可以将许多部分包装到一个函数中以自动执行一些放置。

【讨论】:

  • 太棒了——这个 def 让我开始了!非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
相关资源
最近更新 更多