# Sociogram for stingrays

**URL:** <https://igraph.discourse.group/t/sociogram-for-stingrays/1122>\
**Category:** Usage\
**Tags:** R\
**Created:** [28 February 2022 21:04 UTC](https://igraph.discourse.group/t/sociogram-for-stingrays/1122 "2022-02-28T21:04:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colby\_Kresge](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/colby_kresge/32/689_2.png) [@Colby\_Kresge](https://igraph.discourse.group/u/Colby_Kresge)\
**Post date:** [28 February 2022 21:04 UTC](https://igraph.discourse.group/t/sociogram-for-stingrays/1122/1 "2022-02-28T21:04:40Z")

</div>

using Rstudio, I am trying to make a social diagram of stingrays.  
I have been having two issues:

1. the stingrays denoted by a node 1-30 move location on the plot everytime I re run the code
2. the stingrays that are lower numbers should be in the central  
Is there any way to fix this?  
See screenshot below:  
 ![Screen Shot 2022-02-28 at 3.47.05 PM](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/1e4e1e0730468a5481752542f4c6eda1c605d6cd.jpeg)

my data is in an edge and node list of weights for each individual essentially looks like this:  
sting.edge:  
From To Weight  
1 2 15  
1 3 14  
…

sting.node:  
1  
2  
3  
…

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.x_weight.y)/sum(weight.x_weight.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”)
