Click here to Skip to main content
14,668,125 members
Rate this:
Please Sign up or sign in to vote.
See more:
In R programming - How do I plot a network visualization graph given a matrix X with a 2 column coordinate system:

coordinates <- matrix(c(0.809,0.588,0.309,0.951,-0.309,0.951,-0.809,0.588,-1,0,-0.809,-0.588,-0.309,-0.951,0.309,-0.951,0.809,-0.588,1,0), ncol=2)

...and a quadratic matrix Y as an adjacency matrix:

adjacency <- matrix(c(0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0), ncol=10)

Unfortunately I can only use the standard R Library (that which is pre-installed) and that's why I'm having a hard time figuring it out...

What I have tried:

So far I have this code but the graph it creates is quite "ugly" and gives me a ton of errors:

plotGraph <- function(B){
  
  coordinates <- matrix(c(0.809,0.588,0.309,0.951,-0.309,0.951,-0.809,0.588,-1,0,-0.809,-0.588,-0.309,-0.951,0.309,-0.951,0.809,-0.588,1,0), ncol=2)
  
  adjacency <- matrix(c(0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0), ncol=10)
  
  plot(coordinates)
  
  idx <- which(adjacency>0, arr.ind = T)
  
  number = ncol(adjacency) * nrow(adjacency)
  
  for(i in 1:number){
  arrows(coordinates[idx[i,1],1], coordinates[idx[i,1],2], coordinates[idx[i,2],1], coordinates[idx[i,2],2]) 
}
}
Posted
Updated 10-May-17 2:57am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100