Created
April 28, 2020 23:36
-
-
Save mathzero/689ab1b54d884b02268f19424fb811f0 to your computer and use it in GitHub Desktop.
Plot uk map with data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load packages | |
library(ggmap) | |
library(ggplot2) | |
library(ggthemes) | |
### set up a google API for google static maps at https://developers.google.com/maps/documentation ### | |
# register key | |
register_google(key = "XXXXXXXXXXXXXXX") | |
# save latitude and langitude | |
uk <- c(lon = -4.8536602, lat = 54.3442563) | |
# get google map | |
map <- get_googlemap(location = uk, | |
zoom = 6, # determines how zoomed in map view is. 5 gives most of UK but chops off some of scotland. 6 gives all | |
scale = 4, # essentially dpi | |
center = c(lon = -4.8536602, lat = 54.3442563)) | |
# plot base map | |
fin_map <- ggmap(map) | |
# overlay map with data | |
fin_map + geom_point(aes(x = lon, y = lat), col= "firebrick3", data = MyData) + | |
theme(legend.position="bottom")+ # legend to bottom | |
theme(legend.key = element_rect(colour = NA, fill = NA), legend.box.background = element_blank()) ## remove bg to legend icons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment