I have a data frame with two columns. The first column indicates from where someone comes and the second column includes where someone goes. Like in this example: Someone comes from "a" and goes to "a", "b" or "c". Is there a way in R to plot the network that results of this data using the following data frame? Or has the data frame be transformed further to be able to plot it?
from = c("a")
to = rep(c("a","b","c"),times=c(2,3,5))
data=cbind(from,to)
Thanks in advance.
CodePudding user response:
You can plot this using the igraph package like so:
library(igraph)
graph <- graph_from_edgelist(data)
plot(graph)
CodePudding user response:
You can use the chord diagram as well. Sample data:
from = c("a")
to = rep(c("a","b","c"),times=c(2,3,5))
data=cbind(from,to)
Sample code:
library(circlize)
cols <- hcl.colors(4, "Temps")
chordDiagram(data,
col = cols,
transparency = 0.1,
link.lwd = 1, # Line width
link.lty = 1, # Line type
link.border = 1) # Border color
circos.clear()
Plot: