我正在使用传单包在R中制作地图。该地图基本上是从中国到美国的一条线。但它并没有像我期望的那样。下面是地图的图像。
所以你可以看到中国到美国之间的界线,但它正在越过陆地区域而不是直接的海路。
制作地图的代码如下:
library(leaflet)
structure(list(lat = c(21.4982662200928, 25.3100662231445, 25.8857326507568,
33.5610008239746, 33.9683494567871, 46.2030830383301), lng = c(121.90234375,
131.111709594727, 133.618789672852, 159.100082397461, 165.190643310547,
-123.813652038574), row_rank = structure(1:6, .Label = c("1",
"2", "3", "4", "5", "6"), class = "factor")), .Names = c("lat",
"lng", "row_rank"), row.names = c(NA, -6L), class = "data.frame")
map <- leaflet() %>% addTiles(urlTemplate ="http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/DeLorme_World_Base_Map/MapServer/tile/{z}/{y}/{x}") #"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
map <- map %>%
addCircleMarkers(data=df1, radius = 8, color = 'red', fill = TRUE, label = ~as.character(row_rank), labelOptions=c(noHide=TRUE)) %>%
addPolylines(data=df1, lng = ~lng, lat = ~lat)
map
我该如何纠正?
答案 0 :(得分:6)
这可能有点不寻常,但我在第6点的经度上加了360度,所以-123.813652038574 + 360 = 236.813652038574,并在数据框中改变了这个值,它绘制了我想象的那个你正在寻找什么 - 一条直接的海上航线,而不是跨越各大洲。
library(leaflet)
df1 <- structure(list(lat = c(21.4982662200928, 25.3100662231445, 25.8857326507568,
33.5610008239746, 33.9683494567871, 46.2030830383301), lng = c(121.90234375,
131.111709594727, 133.618789672852, 159.100082397461, 165.190643310547,
-123.813652038574 + 360), row_rank = structure(1:6, .Label = c("1",
"2", "3", "4", "5", "6"), class = "factor")), .Names = c("lat",
"lng", "row_rank"), row.names = c(NA, -6L), class = "data.frame")
map <- leaflet() %>% addTiles() #"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
map <- map %>%
addCircleMarkers(data=df1, radius = 8, color = 'red', fill = TRUE, label = ~as.character(row_rank), labelOptions=c(noHide=TRUE)) %>%
addPolylines(data=df1, lng = ~lng, lat = ~lat)
map