Hi,
I have this sample df with scores and UK post codes:
region.scores <- data.frame(
stringsAsFactors = FALSE,
Shop = c("A","B","C","D","E","F","G",
"H","I","J","K","L","M","N","O",
"P","Q","R","S","T","U","V",
"W","X","Y","Z"),
GoogleSc = c(4,4.5,4.2,4.2,3.6,4.5,4.3,
4.7,4.3,4.3,4.4,4.6,4.5,4.2,4.4,
4.2,3.9,4,3.9,4.3,3.7,4.5,4.6,
4.4,3.5,4.1),
FullPostCode = c("AB16 6HQ","GU12 4NY","HP19 8DP",
"OX16 3TL","LL57 4YH","EX32 8QA",
"SS14 3EQ","BA2 3AY","BT3 9JP",
"B7 5EA","BL3 6HH","BH12 3LL","CF31 3SA",
"BN3 7ES","BS2 0HL","BB11 5UB",
"BL9 7AZ","CT1 2RJ","CF23 9AB","CA2 7AF",
"CM1 2GL","CH1 4NT","S41 8JT",
"CV6 4BQ","RH10 9PG","CR0 4XN"),
PostCode = c("AB16","GU12","HP19","OX16",
"LL57","EX32","SS14","BA2","BT3",
"B7","BL3","BH12","CF31","BN3","BS2",
"BB11","BL9","CT1","CF23","CA2",
"CM1","CH1","S41","CV6","RH10",
"CR0"),
Cor1 = c(57.161,51.251,51.822,52.062,
53.207,51.071,51.575,51.36,54.62,
52.493,53.565,50.737,51.509,50.835,
51.46,53.783,53.592,51.277,51.515,
54.884,51.745,53.202,53.247,52.432,
51.117,51.372),
Cor2 = c(-2.156,-0.731,-0.825,-1.34,
-4.111,-4.018,0.476,-2.377,-5.904,
-1.873,-2.431,-1.926,-3.576,-0.174,
-2.581,-2.252,-2.286,1.087,-3.151,
-2.949,0.457,-2.908,-1.427,-1.507,
-0.157,-0.074),
PostCode2digits = c("AB","GU","HP","OX","LL","EX",
"SS","BA","BT","B7","BL","BH",
"CF","BN","BS","BB","BL","CT","CF",
"CA","CM","CH","S4","CV","RH",
"CR"),
Region = c("Scotland","South East",
"East of England","South East","Wales",
"South West","East of England",
"South West","Northern Ireland","West Midlands",
"North West","South West","Wales",
"South East","South West","North West",
"North West","South East","Wales",
"North West","East of England",
"North West","Yorkshire and the Humber",
"West Midlands","South East",
"Greater London"),
City = c("Aberdeen","Guilford",
"Hemel Hempstead","Oxford","Llandudno",
"Exeter","Southend on Sea","Bath",
"Northern Ireland","Birmingham","Bolton",
"Bournemouth","Cardiff","Brighton",
"Bristol","Blackburn","Bolton",
"Canterbury","Cardiff","Carlisle","Chelmsford",
"Chester","Sheffield","Coventry",
"Redhill","Croydon")
)
region.scores
I can prepare UK map for Google scores using this code:
library(tidyverse)
library(sf)
uk.all <- left_join(uk, region.scores, by = c('name'='PostCode'))
uk.all
uk.all %>% filter(!is.na(GoogleSc))
rs_sf <- st_as_sf(region.scores, coords=c('Cor2','Cor1'), crs=st_crs(uk.all))
GoogleSc.UK <- ggplot()+
geom_sf(data=uk.all,mapping=aes(fill=GoogleSc)) +
scale_fill_gradient(low = "#F8766D", high = "#00BA38") +
labs(title = "Google Scores by region",
fill = "Google Score")
GoogleSc.UK
The maps are almost empty.
Is it possible to apply the score to Region to have the entire UK map coloured?