gpt4 book ai didi

r - 有没有办法在R中制作漂亮的 "flow maps"或 "line area"图?

转载 作者:行者123 更新时间:2023-12-04 03:43:49 25 4
gpt4 key购买 nike

我正在尝试找到一种直接在R中重新创建这样的图的方法(与在R中进行分析后用Inkscape手动绘制它们相反):



第一个看起来应该很简单,但是我找不到适合我需要的东西……第二个要复杂得多,但是似乎应该可行。

这篇Graph flow chart of transition from states帖子让我感到很亲近(已经很棒了,除了我不一定有一个方阵,我想根据我的喜好指定线条的开始/结束位置,并控制粗细和alpha自己的数据)...

是否可以使用ggplot进行此操作(或者,如果看起来不错的话,也可以使用其他类似点阵的方法)?

最佳答案

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

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 )

您可以修改控制点,颜色等以更接近所需的内容。然后,可以将许多作品包装到一个函数中,以使某些放置自动化。

关于r - 有没有办法在R中制作漂亮的 "flow maps"或 "line area"图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24172010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com