1

I am trying to draw the network on map, I am getting the above error. I looked similar stackoverflow questions, but they did not help. I am 100% new to R.

This is data (test.csv):

from,to
1,2
2,3
3,1

This is latitude and longitude data (test1.csv):

id,long,lat
1,19.0759837,72.8776559
2,23.022505,72.5713621
3,28.4594965,77.0266383

I am trying to draw the network using the following code:

library(igraph)
library(maps)
library(geosphere)

map("world", col="skyblue",  border="gray10", fill=TRUE, bg="gray30")

firminfo <- read.csv(file="test1.csv")
supplynet <- read.csv(file="test.csv")


for(i in 1:nrow(supplynet))  {
  node1 <- firminfo[firminfo$id == supplynet[i,]$from,]
  node2 <- firminfo[firminfo$id == supplynet[i,]$to,]

  arc <- gcIntermediate( c(node1[1,]$long, node1[1,]$lat), 
                         c(node2[1,]$long, node2[1,]$lat), 
                         n=2, addStartEnd=TRUE )

  lines(arc, lwd=0.05)
}

This is give the below error:

 Error in .pointsToMatrix(p1) : Wrong length for a vector, should be 2 

How do I resolve this? I am very new to R, any tips would help me.

Henil Shah
  • 137
  • 4
  • 14

0 Answers0