3 columns CSV, to adjacency matrix, to network, to Arcplot

I am trying to convert a 3-column CSV to arcplot. Columns - A, B, Care always in the order of ABC. However, I did not see a way to implement this as arcs, since most approaches apparently used a two-sided edge plot. Therefore, I follow the instructions here to convert to an adjacency matrix.

I recreate the problem below - but do not create artificial data, since one problem is that the CSV may not be read correctly.

Basically, the CSV contains rows where each column is separated by a character ,, but can contain several values ​​separated by a character ;, for example:

ENV;MO,echoic;tact,social 
ENV;MO,mand,physical
OVB,intraverbal,social
ENV;OVB,tact,social
OVB,intraverbal;tact,social
OVB;ENV;MO,intraverbal;mand,social
OVB;ENV;MO,intraverbal;mand,physical;social
ENV;MO,mand,social;physical

, arcplots:

options(stringsAsFactors = F)
lst <- read.csv("abc.csv", header=FALSE)

#this is pretty much straight from the link above
d <- do.call(rbind, lst)
edges <- rbind(d[ ,1:2], d[ ,2:3])
g <- graph.data.frame(edges, directed=TRUE)
adj <- as.matrix(get.adjacency(g)) 
g2 <- new("graphAM", adjMat=adj, edgemode="directed")
plot(g2, attrs = list(graph = list(rankdir="LR"), node = list(fillcolor = "lightblue")))

, . A, B, C. , A, ; B, , , , intraverbalmandintraverbal; tact C, C.

: ABC ,

OVB; ENV, MO, intraverbal; MAND,

A (OVB & ENV & MO) → B ( & mand) → C ()

, , , PDF- R

+4
2

( ...):

# of course you need to install arcdiagram first
# as described in the pdf
library(arcdiagram) 

DF <- read.table(text=
"ENV;MO,echoic;tact,social 
ENV;MO,mand,physical
OVB,intraverbal,social
ENV;OVB,tact,social
OVB,intraverbal;tact,social
OVB;ENV;MO,intraverbal;mand,social
OVB;ENV;MO,intraverbal;mand,physical;social
ENV;MO,mand,social;physical",sep=',')

# replace ";" with "&\n"
DF[] <- lapply(DF,function(x)gsub(';',' &\n',x))

# create adjacency matrix
m <- rbind(as.matrix(DF[,1:2]),as.matrix(DF[,2:3]))

# plot...
arcplot(m ,col.arcs='DodgerBlue',lwd.arcs=2,col.labels='black',las=2)

enter image description here

+3

, . :

require(igraph)
df[]<-lapply(df,strsplit,";")
el<-as.matrix(do.call(rbind,apply(df,1,expand.grid)))
g<-graph_from_edgelist(rbind(el[,-3],el[,-1]))
plot(g)

enter image description here

DATA

df<-structure(list(V1 = c("ENV;MO", "ENV;MO", "OVB", "ENV;OVB", "OVB", 
"OVB;ENV;MO", "OVB;ENV;MO", "ENV;MO"), V2 = c("echoic;tact", 
"mand", "intraverbal", "tact", "intraverbal;tact", "intraverbal;mand", 
"intraverbal;mand", "mand"), V3 = c("social", "physical", "social", 
"social", "social", "social", "physical;social", "social;physical"
)), .Names = c("V1", "V2", "V3"), row.names = c(NA, -8L), class = "data.frame")
+4

All Articles