简体   繁体   English

R网络软件包-节点属性

[英]R Network Package - node attributes

I've recently started to learn R, with specific interest in network modeling applications. 我最近开始学习R,对网络建模应用程序特别感兴趣。 I've made a sample dataset and would like to visualize it, eventually getting to rigorous statistical network analysis. 我制作了一个样本数据集,并希望对其进行可视化,最终进行严格的统计网络分析。

The example is a high school friendship network. 例子是一个高中的友谊网络。 The node attributes are found in HS1_Node_Attributes.csv and the adjacency matrix is found in HS1_adjacency_matrix. 节点属性位于HS1_Node_Attributes.csv中,而邻接矩阵位于HS1_adjacency_matrix中。 I'm able to visualize the network, though I'm having trouble with node attributes (characteristics of the people). 尽管遇到节点属性(人员特征)方面的麻烦,但我可以可视化网络。 I'm using the network package. 我正在使用网络软件包。

The error I get is as follows: 我得到的错误如下:

Error in set.vertex.attribute(g, vertex.attrnames[[i]], vertex.attr[[i]]) : Inappropriate value given in set.vertex.attribute. set.vertex.attribute中的错误(g,vertex.attrnames [[i]],vertex.attr [[i]]):set.vertex.attribute中给出的值不合适。

I have cross-referenced my example with some tutorials online, along with the R Network package documentation. 我已经通过一些在线教程和R Network软件包文档交叉引用了我的示例。 The potential problem could have been the type of my attribute data frame, though I confirmed it was type list, which checks out. 潜在的问题可能是我的属性数据框的类型,尽管我确认它是类型列表,可以进行检出。 So I'm not sure what the problem is. 所以我不确定是什么问题。 Everything works fine (meaning I can successfully create a network object) if I don't take out node attributes (the vertex.attr and the vertex.attrnames arguments), showing me that the rest of the code is sound. 如果我不删除节点属性( vertex.attrvertex.attrnames参数),一切都将正常工作(这意味着我可以成功创建网络对象),这向我表明其余的代码是正确的。 My code is below. 我的代码如下。

high_school1_attributes <- read.table("HS1_Node_Attributes.csv", header = TRUE, 
                     sep = ",")
high_school1_adj <- read.table("HS1_adjacency_matrix.csv", header = TRUE, 
                         row.names = 1, sep = ",")
adj1 <- as.matrix(high_school1_adj)

library("network")

high_school1_network <- network(adj1, vertex.attr = high_school1_attributes,
                            vertex.attrnames = colnames(high_school1_attributes),
                            directed = FALSE, hyper = FALSE, loops = FALSE, 
                            multiple = FALSE, bipartite = FALSE)

You could be automatically converting strings to factors. 您可能会自动将字符串转换为因数。 I can recreate the error by doing: 我可以通过执行以下操作来重新创建错误:

high_school1_attributes <- read.csv(text=
        "Name,Color
        Kermit,green
        Piggy,pink
        Gonzo,blue")
high_school1_adj <- read.csv(text=
        ",From,To
        1,1,3
        2,3,2
        3,2,1",
    row.names = 1)
adj1 <- as.matrix(high_school1_adj)


library("network")

high_school1_network <- network(
        adj1,
        vertex.attr = high_school1_attributes,
        vertex.attrnames = colnames(high_school1_attributes),
        directed = FALSE, hyper = FALSE, loops = FALSE, 
        multiple = FALSE, bipartite = FALSE)

And can fix it by replacing the first statement with: 并可以通过将第一条语句替换为:

high_school1_attributes <- read.csv(text=
        "Name,Color
        Kermit,green
        Piggy,pink
        Gonzo,blue",
    stringsAsFactors=FALSE)

Which you can see works by plotting: 您可以通过绘制以下内容来查看其作品:

library(igraph)
library(intergraph)

hs_graph <- asIgraph(high_school1_network)
plot(hs_graph, vertex.size=8,
    vertex.color=V(hs_graph)$Color,
    vertex.label=V(hs_graph)$Name,
    edge.arrow.size=0.25,layout=layout.fruchterman.reingold)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 r 中使用网络 package 中的属性从节点列表创建没有边的图 - Create graph with no edges from node list with attributes in the network package in r R:创建具有节点属性的“statnet”网络 - R: creating a 'statnet' network with node attributes R / Network Analysis-如何通过节点的属性创建边 - R/Network Analysis - How to create edges by node's attributes 插入网络的节点属性 - interpolate node attributes of a network 如何转换二部网络并使用一层的节点属性作为 igraph (R) 中第二层的边权重 - How to transform a bipartite Network and use node attributes from one level as edge weights in the second level in igraph (R) 在 R 中带网络 package 的桑基图 - Sankey Diagram with Network package in R 尝试使用 R 上的“igraph”package 表示网络,无法添加命名的独立节点 - Trying to represent a Network using the “igraph” package on R, can't add a named independent node function 统计a.network的变化(节点属性的变化) - function to count changes in a network (changes in node attributes) R:将顶点属性添加到网络(使用statnet) - R: Adding vertex attributes to a network (using statnet) 在具有时间序列多个属性的R ts包中 - in R ts package with multiple attributes in time series
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM