在网络图中定义节点形状,并在R中使用附加属性表
我正在绘制网络,其中包含两种不同类型的节点,我想以不同的形状可视化。为此,我制作了一个额外的表,我在其中指定了哪种结构是使用二进制系统的类型。现在,我想在我的情节函数中指定具有1个结构是三角形的结构,而其中的结构为0。 我的网络数据是相邻矩阵的格式(我使用igraph),并且我正在使用ggnet2进行绘图。
这就是我导入数据的方式:
am <- as.matrix(read.csv2("mydata.csv", header = T, row.names = 1))
g <- graph_from_adjacency_matrix(am, mode = "undirected")
attr <- read.csv2("myattributes.csv", header = T, row.names = 1)
这就是我要绘制它的方式,但我不知道如何指定shape
函数,
ggnet2(g, size = "degree", node.color = "darkgreen", shape = ??????)
谢谢您的帮助!
I am working on plotting a Network and it contains two different types of Nodes which I want to visualise with different shapes. For that I made an additional table in which I specified which structure is which type using a binary system. Now I want to specify in my plot function that the structures with 1 are to be triangles and the ones with 0 as circles.
My data for the Network is in the format of an adjacency matrix (I use igraph) and I am using ggnet2 for the plotting of it.
this is how I imported the data:
am <- as.matrix(read.csv2("mydata.csv", header = T, row.names = 1))
g <- graph_from_adjacency_matrix(am, mode = "undirected")
attr <- read.csv2("myattributes.csv", header = T, row.names = 1)
this is how I would plot it but I dont know how to specify the shape
function
ggnet2(g, size = "degree", node.color = "darkgreen", shape = ??????)
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,绘制
igraph
s的软件包 - 引用ggnet2
includeggplot2
,sna
和网络< /代码>以及
InterGraph
作为桥梁。当然,ggnet2更漂亮,但是
igraph
- way是:请注意,我添加了两个
igraph
style形状为vertex-attributes,以g
多于。在ggent2
中,您可以为向量提供形状,但它们可以是任何值(甚至是因子)或数字(通常的灰色圆圈是19
。ggnet2
中的绘图,请注意,如果您在分别加载属性数据后向顶点添加属性(如上所述),则可能是这样的数据的非常 order> order 重要的网络数据活在不同的数据范围或宽松的向量中,以正确地可视化网络。
Note that the package-requirements for plotting
igraph
s withggnet2
includeggplot2
,sna
andnetwork
as well asintergraph
as a bridge.ggnet2 is prettier, sure, but the
igraph
-way is this:Note that I added two
igraph
-style shapes as vertex-attributes tog
above. Inggent2
you can provide a vector with shapes, but they can be any values (even a factor), or numbers (the usual gray circle is19
. Try this out to plot inggnet2
Note that, if you add attributes to your vertices after separately loading attribute data (as you do above), it may be so that the very order of your data matters. Make sure your table import actually works as intended with the correct attribute being assigned to the correct vertex. I find it a good practice to tie all values as attributes on the igraph-object (edge- and vertex attributes alike) rather than letting the network data live in different dataframes or loose vectors to be combined in order to correctly visualise a network.