I am trying to make a cartogram in R to show the number of occurrences in each area of the UK.
My data currently looks like this:
Area Occurences lon lat
1 Greater London East North UK 200 -0.0936496 51.43092
2 Lambeth and Southwark UK 16 -0.1178424 51.49351
3 Black Country UK 58 -2.0752861 52.52005
4 Glasgow UK 45 -4.2518060 55.86424
5 Leeds UK 331 -1.5490774 53.80076
6 Sth Herts or Watford UK 210 -0.3903200 51.65649
I have the longitude and latitude for all of the 120 observations. So far I have used the following code in an attempt to produce a cartogram:
library(rgdal)
library(cartogram)
library(tmap)
library(maptools)
ukgrid = "+init=epsg:27700"
data(wrld_simpl)
afr <- wrld_simpl[wrld_simpl$NAME == "United Kingdom",]
afr <- spTransform(afr, CRS(ukgrid))
# construct cartogram
afrc <- cartogram(afr, "POP2005", itermax=5)
# plot it
tm_shape(afrc) + tm_fill("POP2005", style="jenks") +
tm_borders() + tm_layout(frame=F)
This produces the UK map but I am unsure how to use my own data for the cartogram as opposed to the population data in the 'wrld_simpl' data that the map is based on.
Does anyone have any experience of doing this or know another method to achieve the desired result? Thanks!