简体   繁体   中英

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:

在此处输入图像描述

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:

在此处输入图像描述

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.

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

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

-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 <- 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”)

-fill the density contours 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

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")

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 .

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.

WGS84 bounds:
-8.82 49.79
1.92 60.94 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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