Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All right, I'll bite. I'm not going to use base R because <code>plot</code> is too hard for me to understand, so instead we will be using <code>ggplot2</code>.</p> <pre><code># UK shapefile found via http://www.gadm.org/download uk.url &lt;- "http://www.filefactory.com/file/s3dz3jt3vr/n/GBR_adm_zip" # replace following with your working directory - no trailing slash work.dir &lt;- "C:/Temp/r.temp/gb_map" # the full file path for storing file file.loc &lt;- paste0(work.dir, "/uk.zip") download.file (uk.url, destfile = file.loc, mode = "wb") unzip(file.loc, exdir = work.dir) # open the shapefile require(rgdal) require(ggplot2) uk &lt;- readOGR(work.dir, layer = "GBR_adm2") # use the NAME_2 field (representing counties) to create data frame uk.map &lt;- fortify(uk, region = "NAME_2") # create fake count data... uk.map$count &lt;- round(runif(nrow(uk.map), 0, 2500), 0) # quick visual check ggplot(uk.map, aes(x = long, y = lat, group = group, fill = count)) + geom_polygon(colour = "black", size = 0.5, aes(group = group)) + theme() </code></pre> <p>This generates the output below, which may be similar to what you need.</p> <p><img src="https://i.stack.imgur.com/8vlqD.png" alt="screenshot"></p> <p>Note that we don't explictly specify the gradient in this case - we just leave it up to <code>ggplot</code>. If you wish to specify those details it is possible but more involved. If you go down that route you should create another column in <code>uk.map</code> to allocate each count into one of (say) 10 bins using the <code>cut</code> function. The <code>uk.map</code> data frame looks like this:</p> <pre><code>&gt; str(uk.map) 'data.frame': 427339 obs. of 8 variables: $ long : num -2.05 -2.05 -2.05 -2.05 -2.05 ... $ lat : num 57.2 57.2 57.2 57.2 57.2 ... $ order: int 1 2 3 4 5 6 7 8 9 10 ... $ hole : logi FALSE FALSE FALSE FALSE FALSE FALSE ... $ piece: Factor w/ 234 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ... $ group: Factor w/ 1136 levels "Aberdeen.1","Aberdeenshire.1",..: 1 1 1 1 1 1 1 1 1 1 ... $ id : chr "Aberdeen" "Aberdeen" "Aberdeen" "Aberdeen" ... $ count: num 1549 1375 433 427 1282 ... &gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload