다음 스크립트에서 여러 쌍의 점을 읽고지도에 선을 그립니다.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)
불행하게도,이 때문에 캐나다의 북부 위도의지도의 상단에 거리의 엄청난 왜곡을 초래 : 나는 이상이 줄을 음모 구글에서지도에 끌어 ggmap을 사용하고 있습니다
이것은 직교 플롯으로 전환하면 쉽게 수정할 수 있으며, createMap 함수 내에 projection=mapprojection(orthographic)
을 추가하여 선의 투영 방법을 변경할 수는 있지만 Google에서 얻은지도 이미지의 투영을 변경할 수는 없습니다. - 웹 메르카토르 투영법에 갇혀있다. ggmap을 사용하여이 작업을 수행 할 수있는 방법이 있습니까? 아니면 다른 패키지를 사용해보아야합니까? 그렇다면 무엇을 권하고 싶습니까?
아름다움을위한 upvotes를 얻어야합니다. –