I need some help getting started using igraph in R. I have a .csv file with three columns:
I have the file read into R, and I tried turning it into a dataframe and graphing it that way, but it didn't work. My final goal is to turn this .csv file into a weighted network graph, but I'm not sure how to start.
This (adapted example from the igraph documentation) should get you started:
# Load package
library(igraph)
# Make up data
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David", "David", "Esmeralda"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
weight=c(4,5,5,2,1,1))
# Alternatively, you could read in the data from a similar CSV file as follows:
# relations <- read.csv("relations.csv")
# Load (DIRECTED) graph from data frame
g <- graph.data.frame(relations, directed=TRUE)
# Plot graph
plot(g, edge.width=E(g)$weight)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With