使用R在OpenStreetMap上绘制纬度/经度点

时间:2018-10-12 09:47:35

标签: r ggplot2 gis openstreetmap

我无法将头部缠绕在投影上。我对北欧地区的看法最终指向中部非洲。

我的代码如下。

#Loading packages

library(OpenStreetMap)
library(rgdal)
library(ggplot2)

#defining world map
map <- openmap(c(70,-179), c(-70,179))
plot(map)

#Finding my work place in Northern Europe (Ørbækvej 100, Odense, Denmark from here: https://www.latlong.net/convert-address-to-lat-long.html)
subscr<-data.frame(lat=c(55.381640),
                   lon=c(10.433600))

#I am not sure what this does, but found on the web for a map in Germany: (https://gis.stackexchange.com/questions/209166/plotting-bubbles-on-top-of-openstreetmap-in-r) 
coordinates(subscr)<-~lat+lon
proj4string(subscr)<-CRS("+init=epsg:4326")
points(spTransform(subscr,osm()))
#as can be seen using this method the dot turns up in Eastern Africa


symbols(y = subscr$lon, x = subscr$lat, circles = 1, add = TRUE,
        inches = 0.0001, bg = "darkgreen")
#as can be seen using the method the dot turns up in Western/Mid Africa

有人能解释甚至帮助我把这个点放在丹麦,北欧吗?

2 个答案:

答案 0 :(得分:3)

我不知道您想要哪种地图,但是对于绘制纬度点,leaflet是我的默认选择。.

library( leaflet )
library( magrittr )

subscr<-data.frame(lat=c(55.381640),
                   lon=c(10.433600))

leaflet() %>% addTiles() %>% 
  addCircleMarkers(data = subscr,
                   lat = ~lat, lng = ~lon,
                   color = "blue")

enter image description here

答案 1 :(得分:0)

您是否要使用开放的街道地图?您可能会考虑使用与ggmap很好地交互的ggplot2软件包。但是,有时我在使用ggmap下载开放的街道地图时会遇到麻烦,但是google-maps应该可以工作。

请考虑以下示例。请注意,我通过下载命令删除了地图中不必要的文本。

# download
map <- get_googlemap(center = "Europe", zoom = 3, 
                     style = paste0("feature:administrative.country|",
                                    "element:labels|visibility:off"),
                     filename = "Map",
                     language = "en-EN") # you might want to adjust the language settings

# see what you've got
ggmap(map)

# edit map
ggmap(map)+

  # do some scaling (make it smaller)
  scale_x_continuous(limits = c(-12, 42), expand = c(0, 0)) +
  scale_y_continuous(limits = c(35, 70), expand = c(0, 0))+

  # remove unwanted information
  theme(axis.title.x    = element_blank(),
        axis.title.y    = element_blank(),
        axis.line       = element_blank(),
        axis.ticks      = element_blank(),
        axis.text       = element_blank(),
        plot.title      = element_blank(),
        plot.background = element_blank())+

  # add whatever you like based on your coordinates using annotate()
  annotate("text", x = 10.433600, y = 55.381640, 
           label = "You are here",
           size = 2.4, color = "black", fontface = "bold",
           na.rm = TRUE, hjust = 0.5)

这可以解决您的问题吗?