[R] R maps Help
Frank Rodgers
frodgers at frankrodgers.com
Sat Feb 9 17:06:37 CET 2013
I am fairly new to R and am plotting flight data on a map. Everything is
working well except the size of the map is really too small to show the data
effectively and I can't seem to figure out how to make the output map
larger. Do I need to change the device characteristics or is it a map.???
call. Here is the code:
library(maps)
library(geosphere)
airports <- read.csv("airports.csv", header=TRUE)
flights <- read.csv("FSRflights.csv", header=TRUE, as.is=TRUE)
checkDateLine <- function(l){
n<-0
k<-length(l)
k<-k-1
for (j in 1:k){
n[j] <- l[j+1] - l[j]
}
n <- abs(n)
m<-max(n, rm.na=TRUE)
ifelse(m > 30, TRUE, FALSE)
}
clean.Inter <- function(p1, p2, n, addStartEnd){
inter <- gcIntermediate(p1, p2, n=n, addStartEnd=addStartEnd)
if (checkDateLine(inter[,1])){
m1 <- midPoint(p1, p2)
m1[,1] <- (m1[,1]+180)%%360 - 180
a1 <- antipode(m1)
l1 <- gcIntermediate(p1, a1, n=n, addStartEnd=addStartEnd)
l2 <- gcIntermediate(a1, p2, n=n, addStartEnd=addStartEnd)
l3 <- rbind(l1, l2)
l3
}
else{
inter
}
}
add_lines <- function(){
pal <- colorRampPalette(c("#00FF00", "#FF0000"))
colors <- pal(100)
fsub <- flights[flights$airline == "FSR",]
fsub <- flights[order(flights$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,]
p1 <- c(air1[1,]$long, air1[1,]$lat)
p2 <- c(air2[1,]$long, air2[1,]$lat)
inter <- clean.Inter(p1,p2,n=100, addStartEnd=TRUE)
colindex <- round( (fsub[j,]$cnt / maxcnt) * length(colors))
lines(inter, col=colors[colindex], lwd=0.1)
}
}
map_usa <- function(){
xlim <- c(-171.738281, -56.601563)
ylim <- c(12.039321, 71.856229)
map("world", col="#191919", fill=TRUE, bg="#736F6E", lwd=0.05, xlim=xlim,
ylim=ylim)
add_lines()
}
map_world <- function(){
map("world", col="#191919", fill=TRUE, bg="#736F6E", lwd=.1)
add_lines()
}
map_world()
--
View this message in context: http://r.789695.n4.nabble.com/R-maps-Help-tp4658030.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list