В следующем скрипте я прочитал несколько пар точек и нарисовал линии на карте. Я использую ggmap тянуть в карте от Google, чтобы построить эти строки более:Создание орфографической карты с использованием ggmap
source('./library/latlong2state.R')
library(maps)
library(mapproj)
library(mapdata)
library(geosphere)
library(ggmap)
fileName = "_CanadaData/CanadaHospitalComplete.csv"
getLineColor <- function(val) {
pal <- colorRampPalette(lineColours)
colors <- pal(80)
val.log <- log(val)
if (val > 50) {
col <- colors[80]
} else {
colindex <- max(1, round(80 * val/50))
col <- colors[colindex]
}
return(col)
}
# Load the data
location <- read.csv(fileName, stringsAsFactors=FALSE)
# Omit locations that are not on the map of focus (not needed for city maps unless they are on a border)
location$state <- latlong2state(data.frame(location$lng, location$lat))
location$nearstate <- latlong2state(data.frame(location$lngnear, location$latnear))
location <- na.omit(location)
createMap <- function(bbox, thedata, mapzoom=3, linesize=0.6, pointsize=2) {
basemap <- get_map(location=bbox, zoom=mapzoom, source='google', maptype="roadmap", color="color")
ggmap(basemap) + geom_segment(aes(x=lng, xend=lngnear, y=lat, yend=latnear, color=dist_miles), size=0.6, data=thedata) + geom_point(aes(x=lngnear, y=latnear), size=2, color="#000000", border="black", data=thedata) + scale_color_gradient(low="blue", high="red", limits=c(0, max(thedata$dist_miles))) + coord_map("orthographic")
}
# Country bounding box c(left, bottom, right, top)
canada <- c(-140.920514, 42.016722, -52.524864, 83.2911)
createMap(canada, location)
К сожалению, это приводит к массовым искажениями расстояния в верхней части карты из-за северной широты Канады:
Это можно легко устранить, переключившись на орфографический сюжет, и я могу изменить проекцию того, как строятся строки, добавив projection=mapprojection(orthographic)
внутри функции createMap, но я не могу изменить проекцию изображения карты, которое я получаю от Google - он застревает в проекции Web Mercator. Есть ли способ сделать это с помощью ggmap, или мне придется попробовать другой пакет? Если да, что вы рекомендуете?
Вы должны получить бонусы за красоту. –