简体   繁体   English

在 ggmap 和 ggplot2 中为英国绘制 map

[英]Plotting map for UK, in ggmap & ggplot2

All,全部,

if如果

Germany = map_bounds <- c(left = 5, bottom = 47, right = 16, top = 56)

what is the UK?什么是英国?

UK =英国 =

Try any of these options:尝试以下任何选项:

library(maps)       
library(mapdata)    
#Option 1
map('worldHires',
    c('UK', 'Ireland', 'Isle of Man','Isle of Wight'),
    xlim=c(-11,3), ylim=c(49,60.9)) 

Output: Output:

在此处输入图像描述

Or:或者:

library(ggplot2)
library(maps)
#Data
worldmap = map_data('world')
#Option 2
ggplot() + geom_polygon(data = worldmap, 
                        aes(x = long, 
                            y = lat, 
                            group = group,
                            ),
                        fill = 'gray90', 
                        color = 'black') + 
  coord_fixed(xlim = c(-10,3), 
              ylim = c(50.3, 59))

Output: Output:

在此处输入图像描述

Thanks for the help above here is the nearly complete code, i just need to understand which bit, and how, to mod the heatmap polygons to be transparent, they're currently obstructing the map beneath.感谢上面的帮助,这里是几乎完整的代码,我只需要了解哪个位以及如何将热图多边形修改为透明,它们目前阻碍了下面的 map。

library(ggplot2) library(ggmap) library(RColorBrewer)库(ggplot2) 库(ggmap) 库(RColorBrewer)

coords.data <- read.csv(file="~/Desktop/locations.csv”) coords.data <- read.csv(file="~/Desktop/locations.csv")

-UK bounds map_bounds <- c(left = -2.5, bottom = 51, right = 1.5, top = 54) -UK bounds map_bounds <- c(left = -2.5, bottom = 51, right = 1.5, top = 54)

coords.map <- get_stamenmap(map_bounds, zoom = 10, maptype = "toner-lite”) coords.map <- get_stamenmap(map_bounds, zoom = 10, maptype = "toner-lite")

coords.map <- ggmap(coords.map, extent="device", legend="none”) coords.map <- ggmap(coords.map, extent="device", legend="none")

-heat map layer: Polygons with fill color based on relative frequency of coordinates coords.map <- coords.map + stat_density2d(data=coords.data, aes(x=Longitude, y=Latitude, fill=..level.., alpha=..level..), geom="polygon”) -heat map layer: Polygons with fill color based on relative frequency of coordinates coords.map <- coords.map + stat_density2d(data=coords.data, aes(x=Longitude, y=Latitude, fill=..level.., alpha=..level..), geom="polygon")

-fill the density contours coords.map <- coords.map + scale_fill_gradientn(colours=rev(brewer.pal(7, "Spectral"))) -填充密度轮廓 coords.map <- coords.map + scale_fill_gradientn(colours=rev(brewer.pal(7, "Spectral")))

-Add the coords,color red and define shape -Shapes: http://sape.inf.usi.ch/quick-reference/ggplot2/shape - 添加坐标,颜色为红色并定义形状 - 形状: http://sape.inf.usi.ch/quick-reference/ggplot2/shape

coords.map <- coords.map + geom_point(data=coords.data, aes(x=Longitude, y=Latitude), fill="red", shape=23, alpha=0.4) coords.map <- coords.map + geom_point(data=coords.data, aes(x=Longitude, y=Latitude), fill="red", shape=23, alpha=0.4)

coords.map <- coords.map + theme_bw() ggsave(filename="./coords.png") coords.map <- coords.map + theme_bw() ggsave(filename="./coords.png")

In addition to @Duck 's answer you can get the WGS84 (ie Longitude and Latitude) bounds of any country by searching for that country on epsg.io .除了@Duck 的答案,您还可以通过在epsg.io上搜索该国家/地区来获得任何国家/地区的 WGS84(即经度和纬度)范围。

The UK, for example, uses British National Grid (EPSG 27700) so if you select that projection is gives you WGS84 bounds that you can use for your map bounds.例如,英国使用英国国家电网 (EPSG 27700) ,因此如果您使用 select,该投影将为您提供 WGS84 边界,您可以将其用于 map 边界。

WGS84 bounds:
-8.82 49.79
1.92 60.94 

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

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