在网络图中定义节点形状,并在R中使用附加属性表

发布于 2025-02-13 15:36:18 字数 567 浏览 1 评论 0原文

我正在绘制网络,其中包含两种不同类型的节点,我想以不同的形状可视化。为此,我制作了一个额外的表,我在其中指定了哪种结构是使用二进制系统的类型。现在,我想在我的情节函数中指定具有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有影子陪我不离不弃 2025-02-20 15:36:18

请注意,绘制igraph s的软件包 - 引用ggnet2 include ggplot2sna网络< /代码>以及InterGraph作为桥梁。

当然,ggnet2更漂亮,但是igraph - way是:

g <- erdos.renyi.game(100,100,'gnm')
V(g)$shape <- sample(c('csquare','circle'), 100, replace=T)
plot(g, vertex.label = NA)

请注意,我添加了两个igraph style形状为vertex-attributes,以g多于。在ggent2中,您可以为向量提供形状,但它们可以是任何值(甚至是因子)或数字(通常的灰色圆圈是19ggnet2中的绘图

ggnet2(g, shape=19)
ggnet2(g, shape=10+round(1:100/10))
ggnet2(g, shape=factor(V(g)$shape))
V(g)$shape <- sample(c('One shape','Another shape'), 100, replace=T)
ggnet2(g, shape=V(g)$shape, size = "degree", node.color = "darkgreen")

,请注意,如果您在分别加载属性数据后向顶点添加属性(如上所述),则可能是这样的数据的非常 order> order 重要的网络数据活在不同的数据范围或宽松的向量中,以正确地可视化网络。

Note that the package-requirements for plotting igraphs with ggnet2 include ggplot2, sna and network as well as intergraph as a bridge.

ggnet2 is prettier, sure, but the igraph-way is this:

g <- erdos.renyi.game(100,100,'gnm')
V(g)$shape <- sample(c('csquare','circle'), 100, replace=T)
plot(g, vertex.label = NA)

Note that I added two igraph-style shapes as vertex-attributes to g above. In ggent2 you can provide a vector with shapes, but they can be any values (even a factor), or numbers (the usual gray circle is 19. Try this out to plot in ggnet2

ggnet2(g, shape=19)
ggnet2(g, shape=10+round(1:100/10))
ggnet2(g, shape=factor(V(g)$shape))
V(g)$shape <- sample(c('One shape','Another shape'), 100, replace=T)
ggnet2(g, shape=V(g)$shape, size = "degree", node.color = "darkgreen")

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文