14,668,125 members
Rate this:
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)

Top Experts
Last 24hrsThis month
 OriginalGriff 225 CPallini 115 Richard MacCutchan 110 Rick York 85 Richard Deeming 60
 OriginalGriff 5,176 Richard MacCutchan 3,535 CPallini 2,197 Sandeep Mewara 1,535 Patrice T 1,256

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