有没有一种方法可以制作出精美的“流程图",或“行区域" R中的图形? [英] Is there a way to make nice "flow maps" or "line area" graphs in R?

查看:108
本文介绍了有没有一种方法可以制作出精美的“流程图",或“行区域" R中的图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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've done the analysis in R):

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

The first one seems like it should be straight forward, but I'm not able to find anything that fits my needs... the second one is much more complicated, but also seems like it should be doable.

这篇帖子从状态过渡的图形流程图大约一样近(它已经很棒了,除了我不一定有一个方形矩阵,我想根据自己的数据为线条的起始/结束位置指定厚度和Alpha的控制权).

This post Graph flow chart of transition from states gets me about as close (it's kind of awesome already, except I don't necessarily have a square matrix, and I'd like to designate a start/end location for my lines with control over thickness and alpha based on my own data)...

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

Is it possible to do this using ggplot (or maybe something else like lattice, if it looks nice)?

推荐答案

以下是使用基础图形在左侧图形上入门的示例(如果要使用网格图形,也有xspline函数,我不知道)不知道如何将它们与ggplot2合并,但晶格可能不会太难):

Here is an example to get started on the left graph using base graphics (there are xspline functions for grid graphics as well if you want to use those, I don't know how to incorporate them with ggplot2, but lattice probably would not be too hard):

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

使用一些不同的方法为正确的图形提供一些起始代码:

And some starting code for the right graph using a little 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 )

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

You can modify the control points, colors, etc. to get closer to what you want. Many of the pieces could then be wrapped into a function to automate some of the placing.

这篇关于有没有一种方法可以制作出精美的“流程图",或“行区域" R中的图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆