Hi nirgrahamuk,
I tried to follow some of the similar code you provided with the example.
I've attached my code below and a figure from it.
There are two issues I keep encountering:
- Each node moves location in the plot every time the plot line is rerun
- The individuals with the lowest number (1:~10) I hypothesized would be central due to their weights being higher. Is there a modification that can be made in the plot to display this?
library(readr)
Import Data
link <- read_csv("~/Desktop/sting.edge.csv")
node <- read.csv("~/Desktop/sting.node.csv")
examine
head(node)
head(link)
nrow(node); length(unique(node$Name))
nrow(link); nrow(unique(link[,c("From", "To")]))
link <- link[order(link$From, link$To),]
colnames(link)[3] <- "weight"
rownames(link) <- NULL
library('igraph')
Weights
wgt_df2 <- enframe(sort(table(unlist(link))^3),
value="weight")
edgelist2b <- left_join(link,
wgt_df2,by=c("From"="name")) %>% left_join(wgt_df2,
by=c("To"="name")) %>%
mutate(weight=(weight.xweight.y)/sum(weight.xweight.y)/spread_factor)
plotting
g2 <- graph_from_data_frame(link)
is_weighted(g2)
??node_size_factor
enframe(sort(strength(g2))) %>%
mutate(name=forcats::as_factor(name)) %>%
ggplot(aes(x=as_factor(as.integer(name)),y=value)) + geom_text(aes(label=name))
node_size_factor <-.03
plot(g2,layout= layout_with_fr(g2),rescale=TRUE,vertex.size=strength(g2)*node_size_factor,
remove.multiple=F, remove.loops=T, edge.arrow.size=.001, vertex.color="lightblue")