[R] Error : Error in if (antipodal(p1, p2))
shabsae
shabsae at gmail.com
Sun Nov 25 08:04:07 CET 2012
Hey,
I'm trying to build something like this
http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/
but with my own data in csv files.
The code runs well if I use the same csv files as the author, but with mine
, this is what I get
*Code*
library(maps)
library(geosphere)
map("world")
xlim <- c(-180.00, 180.00)
ylim <- c(-90.00, 90.00)
map("world", col = "#f2f2f2", fill = TRUE, bg = "white", lwd = 0.05,xlim =
xlim, ylim = ylim)
airports <- read.csv("/Users/shabnam/Desktop/airports.csv", as.is=TRUE,
header=TRUE)
flights <- read.csv("/Users/shabnam/Desktop/flights.csv", as.is=TRUE,
header=TRUE)
pal <- colorRampPalette(c("#545454", "white"))colors <- pal(100)
map("world", col="#303030", fill=TRUE, bg="black", lwd=0.05, xlim=xlim,
ylim=ylim)
fsub <- flights[flights$airline == "AA",]
fsub <- fsub[order(fsub$cnt),]
maxcnt <- max(fsub$cnt)
for (j in 1:length(fsub$airline))
{
air1 <- airports[airports$iata == fsub[j,]$airport1,]
air2 <- airports[airports$iata == fsub[j,]$airport2,]
inter <- gcIntermediate(c(air1[1,]$long, air1[1,]$lat), c(air2[1,]$long,
air2[1,]$lat), n=100, addStartEnd=TRUE)
colindex <- round( (fsub[j,]$cnt / maxcnt) * length(colors) )
lines(inter, col=colors[colindex], lwd=0.8)
}
--
View this message in context: http://r.789695.n4.nabble.com/Error-Error-in-if-antipodal-p1-p2-tp4650712.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list