简体   繁体   English

使用ggmap世界地图

[英]Using ggmap map of the world

I am trying to obtain a simple raster map of the entire world, using the ggmap package / get_map functionality (see code below) in combination with ggplot2 . 我正在尝试使用ggmap包/ get_map功能(请参阅下面的代码)结合ggplot2获取整个世界的简单栅格地图。 The zoom levels only go towards "3", and do not allow further zooming out 缩放级别仅朝向“3”,并且不允许进一步缩小

it seems impossible to get a world map (as documented in the ggmap description: ( "maps of the whole world currently not supported" ). Perhaps due to a lack of understanding why this is not possible / supported, is there a work-around / alternative solution to have a world map view? 获得世界地图似乎是不可能的(如ggmap描述中所述ggmap "maps of the whole world currently not supported" 。)也许由于缺乏理解为什么这是不可能/不支持的,是否有解决办法/替代解决方案有世界地图视图?

EDIT / UPDATE on QUESTION: I have tried to use the world-map as suggested - but for some reason i don't understand why it doesn't allow me to plot points in the graph (which was the original aim, and does work in ggmap )- feel that i am doing something stupid / making basic mistake. 关于问题的编辑/更新:我试图按照建议使用世界地图 - 但由于某种原因我不明白为什么它不允许我在图中绘制点(这是最初的目标,并且确实有效在ggmap ) - 觉得我做了一些愚蠢的事情/犯了一些基本的错误。 I get error message "Error in eval(expr, envir, enclos) : object 'group' not found" 我收到错误消息"Error in eval(expr, envir, enclos) : object 'group' not found"

EDIT- unfortunately i get an error message using OpenStreetMap (java error. working on fixing this - but non OpenStreetMap solutions would be great...) 编辑 - 不幸的是我使用OpenStreetMap收到错误消息(java错误。正在修复此问题 - 但非OpenStreetMap解决方案会很棒......)

To summarize - the ggmap approach works with geom_point , but i cannot get a whole world map. 总结一下 - ggmap方法适用于geom_point ,但我无法获得整个世界地图。 the worldmap approach should work, but for some reason cannot get points to plot..... 世界worldmap方法应该工作,但由于某种原因无法获得积分.....

NEW CODE per below: 以下新代码:

ggmap approach: ggmap方法:

library(ggmap)
library(ggplot2)

reclat=c(50,20,30,40)
reclong=c(30,40,30,50)         
points=as.data.frame(cbind(reclat,reclong))

al1 = get_map(location = 'Europe', zoom = 3, color="bw",maptype = "satellite")
map = ggmap(al1)
map 

#this works
map+geom_point(data=points, aes(x=reclong, y=reclat, colour="red"))

worldmap approach: worldmap方法:

world <- map_data("world")
worldmap <- ggplot(world, aes(x=long, y=lat, group=group)) +
  geom_path() +
  scale_y_continuous(breaks=(-2:2) * 30) +
  scale_x_continuous(breaks=(-4:4) * 45)

#this works
worldmap + geom_point(aes(50, 30, colour="red"))

#this doesnt work
worldmap + geom_point(data=points, aes(x=reclong, y=reclat, colour="red"))

You can try the OpenStreetMap package, which has access to many different map servers, though not GoogleMaps. 您可以尝试使用OpenStreetMap包,它可以访问许多不同的地图服务器,但不能访问GoogleMaps。

library(OpenStreetMap)
library(ggplot2)
map <- openmap(c(70,-179),
               c(-70,179),zoom=1)
map <- openproj(map)


reclat <- c(50,20,30,40)
reclong <- c(30,40,30,50)         
autoplot(map) + geom_point(aes(x=reclong,y=reclat))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM