1

I have a map of the UK at present using

library(maps)

UK <- map_data("world") %>%
  filter(region == "UK")

But how do i filter out England, Scotland and Wales and leave Northern Ireland? I have tried changing the region to Northern Ireland but it doesn't recognise it.

Any help would be much appreciated

Kevin Arseneau
  • 6,186
  • 1
  • 21
  • 40

1 Answers1

2

There is a subregion column available.

unique(UK$subregion)

# [1] "Isle of Wight"    "Wales"            "Northern Ireland" "Scotland"         "Great Britain"

If you only want Northern Ireland you can adapt your code to...

NI <- map_data("world") %>%
  filter(region == "UK" & subregion == "Northern Ireland")

head(NI)

#        long      lat group order region        subregion
# 1 -6.218018 54.08872   572 40086     UK Northern Ireland
# 2 -6.303662 54.09487   572 40087     UK Northern Ireland
# 3 -6.363672 54.07710   572 40088     UK Northern Ireland
# 4 -6.402588 54.06064   572 40089     UK Northern Ireland
# 5 -6.440284 54.06363   572 40090     UK Northern Ireland
# 6 -6.548145 54.05728   572 40091     UK Northern Ireland

Then a basic plot...

ggplot(NI, aes(x = long, y = lat)) +
  geom_polygon() +
  coord_map() +
  ggthemes::theme_map()  

To produce...

enter image description here

Kevin Arseneau
  • 6,186
  • 1
  • 21
  • 40
  • Kevin now that i have my map is there any way to add districts to my map or give it more context? – cooksteve09 Apr 17 '18 at 13:31
  • @cooksteve09, there is not more detailed boundary levels in the `maps` package. You will need to use another source, [Here](https://www.opendatani.gov.uk/dataset/boundary-commission-for-northern-ireland-revised-proposals/resource/250e12b8-d8a7-41b6-98d4-f8862449d61c) is an example of GeoJSON data and you can use [this](https://stackoverflow.com/questions/24183007/is-it-possible-to-read-geojson-or-topojson-file-in-r-to-draw-a-choropleth-map) answer as an example to plot. – Kevin Arseneau May 12 '18 at 02:10