阅读背景:

ggmap地图样式库?现在CloudMade不再提供API

来源:互联网 

I'm not sure if this is the right place to ask this question, but does anybody have suggestions for accessing different map styles that can be used for ggmap? CloudMade no longer gives API keys to accounts which are not 'enterprise accounts'.

我不确定这是否是提出这个问题的正确位置,但有没有人建议访问可用于ggmap的不同地图样式? CloudMade不再为不是“企业帐户”的帐户提供API密钥。

From "ggmap: Spatial Visualization with ggplot2" (Kahle and Wickham), they suggest to either use Stamen or Google maps, but I'm looking for a different style than offered by these.

从“ggmap:使用ggplot2进行空间可视化”(Kahle和Wickham),他们建议使用Stamen或Google地图,但我正在寻找与这些不同的风格。

Can anybody suggest a repository of map styles that could be used for ggmap?

任何人都可以建议可以用于ggmap的地图样式库吗?

Cheers

干杯

4 个解决方案

#1


2  

You can get a simple land - water contrast using the maps package:

您可以使用地图包获得简单的陆地 - 水对比:

Set the boundaries of the map with xlim and ylim.

使用xlim和ylim设置地图的边界。

library(maps)
library(ggplot2)

map <- fortify(map(fill = TRUE, plot = FALSE))

ggplot(data = map, aes(x=long, y=lat, group = group)) +
   geom_polygon(fill = "ivory2") +
   geom_path(colour = "black") +
   coord_cartesian(xlim = c(137, 164), ylim = c(-14, 3.6)) +
   theme(panel.background = element_rect(fill = "#F3FFFF"),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank())

The map is a bit clunky, but high resolution maps are available in the mapdata package>

地图有点笨重,但mapdata包中提供了高分辨率地图

library(mapdata)
map <- fortify(map("worldHires", fill = TRUE, plot = FALSE))

ggplot(data = map, aes(x=long, y=lat, group = group)) +
   geom_polygon(fill = "ivory2") +
   geom_path(colour = "black") +
   coord_cartesian(xlim = c(135, 165), ylim = c(-15, 0)) +  # Papua New Guinea
   theme(panel.background = element_rect(fill = "#F3FFFF"),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank())  # Be patient

Or a single country can be selected.

或者可以选择一个国家。

map <- fortify(map("worldHires", fill = TRUE, plot = FALSE))

ggplot(data = subset(map, region == "Papua New Guinea"), aes(x=long, y=lat, group = group)) +
   geom_polygon(fill = "ivory2") +
   geom_path(colour = "black") +
   theme(panel.background = element_rect(fill = "#F3FFFF"),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank()) 

#2


2  

Google maps has a little know style feature:

Google地图有一点鲜为人知的风格特征:

https://developers.google.com/maps/documentation/javascript/styling

https://developers.google.com/maps/documentation/javascript/styling

As another comment noted, get_map is just a wrapper for get_googlemap, etc. And then get_googlemap is just a wrapper for a series of http calls to get map tiles, so it seems possible to hack up the code from get_googlemap a bit so instead of pointing at the basic google map style, it would grab styled tiles.

正如另一条评论指出的那样,get_map只是get_googlemap等的包装器。然后get_googlemap只是一系列http调用的包装器,可以获取地图图块,所以似乎可以从get_googlemap中修改代码,而不是指向在基本的谷歌地图风格,它会抓住风格的瓷砖。

I may work on this approach over the next month as I have a need for a similar basemap as requested by OP.

我可能会在下个月开始研究这种方法,因为我需要OP所要求的类似底图。

#3


0  

This is the function definition for get_map:

这是get_map的函数定义:

function (location = c(lon = -95.3632715, lat = 29.7632836), 
    zoom = "auto", scale = "auto", maptype = c("terrain", "satellite", 
        "roadmap", "hybrid", "toner", "watercolor"), messaging = FALSE, 
    urlonly = FALSE, filename = "ggmapTemp", crop = TRUE, color = c("color", 
        "bw"), source = c("google", "osm", "stamen", "cloudmade"), 
    api_key) 

and, there's a series of if statements in it that limit it to the source = … options.

并且,其中有一系列if语句将其限制为source = ...选项。

You can combine them with the various maptype = … options to try to get something that works for you.

您可以将它们与各种maptype = ...选项结合使用,以尝试获取适合您的内容。

#4


0  

This currently works best with the development version of ggmap. To use this you need to run devtools::install_github("dkahle/ggmap")

目前最适合ggmap的开发版本。要使用它,你需要运行devtools :: install_github(“dkahle / ggmap”)

I have developed a new package ggmapstyles, which should help with this problem: https://github.com/mikey-harper/ggmapstyles . It provides an easy way of selecting themes from Snazzy Maps, which has over 16,000 different styles premade and allows you to create custom designs.

我开发了一个新的包ggmapstyles,它应该有助于解决这个问题:https://github.com/mikey-harper/ggmapstyles。它提供了一种从Snazzy Maps中选择主题的简便方法,它有超过16,000种不同的预制样式,并允许您创建自定义设计。

To use a design, go to Snazzymaps and find a style you like, and then copy the URL into the function get_snazzymap() using the mapRef argument:

要使用设计,请转到Snazzymaps并找到您喜欢的样式,然后使用mapRef参数将URL复制到函数get_snazzymap()中:

devtools::install_github("mikey-harper/ggmapstyles")
library(ggmapstyles)

map <- get_snazzymap(center = 'Southampton, UK', 
                     mapRef = "https://snazzymaps.com/style/72543/assassins-creed-iv")
ggmap(map)

Will plan on developing this further, and potentially merge it with ggmap in the future :)

计划进一步开发这个,并可能在未来将其与ggmap合并:)


分享到: