2017-05-12 1 views
0


2 모드 네트워크에서 다른 노드를 시각화하는 데 문제가 있습니다. 누군가가 실수를 찾도록 도울 수 있기를 바랍니다.
다음과 같은 관련 Q & A를 확인했습니다. How to create a bipartite network in R with igraph or tnet 또는 Converting data form for 2mode network in r 그러나 지침에 따라 문제를 해결할 수는 없습니다.두 모드 네트워크 노드의 색이 다릅니다.

그래서 여기에 내가 한 것입니다. 두 열 (위치 & 칭의)이있는 csv.file이 있습니다. 그것은 다음과 같습니다

title of the file: mydata.csv 
id position    justification 
[1] contra solidarity legal regulations 
[2] pro solidarity  no justification  
[3] pro solidarity  political solidarity 
[4] pro solidarity  political solidarity 
[5] pro solidarity  legal regulations 
... (in total, 620 observations/rows of 2 variables) 

나는 작업 및 패키지 & 및 노드/정점에 대해 서로 다른 색으로 을 만들려고합니다. R은 파일을 읽고 스크립트는 정상적으로 작동합니다 (오류 없음) :

EC_data <- read.csv("Mydata.csv", sep=";") 
EC_data 

library(statnet) 
library(devtools) 

euro_network <- network(EC_data, matrix.type="edgelist", sep=";") 
euro_network 

# overview about the network 
summary(euro_network, print.adj=FALSE) 

# for 2-mode networks 
detach(package:statnet) 
library(igraph) 

# bipartite/2-mode network is created from edge lists 
bn <- graph.data.frame(EC_data, directed=FALSE) 
bn 

# telling igraph that this is bipartite graph 
V(bn)$type <- V(bn)$type %in% EC_data[,1] 
bn 
plot(bn) 

# plotting the network 
plot.igraph(bn,layout=layout.fruchterman.reingold) 

# creating an vertex attribute to have different colors 
V(bn)$type <- V(bn)$name %in% bn[,1] 
bn 
colors <- c("green", "red") 
# green for 'contra solidarity', red for 'pro solidarity' 
plot(bn, vertex.color=colors[V(bn)$type+1]) 

그러나 작동하지 않습니다. 모든 노드의 색깔이 같고 그 이유를 모르겠습니다. 또한 R과 igraph를 시작하기 때문에 근본적으로 무언가를 놓치거나 완전히 고려하지 않은 느낌이 들었습니다.

데이터 또는 스크립트의 문제점은 무엇입니까?

도움이나 제안을 매우 환영합니다!

답변

1

은 도움이 대신

library(igraph) 

col <- c("#a0d468", "#ffce54") 
shape <- c("circle", "square") 


d_edgelist <- read.csv("G:\\DATA.csv") 

summary(d_edgelist) 

library(igraph) 
g <- graph.data.frame(d_edgelist, directed = FALSE) 
g <- simplify(g) 
V(g)$type <- FALSE 
V(g)$type[V(g)$name %in% d_edgelist[, 1]] <- TRUE 
g.proj <- bipartite.projection(g) 
plot(g, layout = layout.bipartite, 
    vertex.size = 40, 
    vertex.shape = shape[as.numeric(V(g)$type) + 1], 
    vertex.color = col[as.numeric(V(g)$type) + 1], 
    edge.color = "#333333", 
    edge.width = E(g)$weight * 2 
) 
+0

감사를 사용해보십시오. 괜찮 았어! 그래서, 제 실수는 V (g) $ 타입 명령이었고 프로젝션을하지 않았습니다. 맞습니까? –

관련 문제