Ok, I think we are getting there but my problem is with the uk file.
Nevertheless, I don't know what the problem is. Did ron ran this code?
My entire code looks like this:
library(tidyverse)
library(sf)
#Download UK postcode polygon Shapefile
download.file(
"http://www.opendoorlogistics.com/wp-content/uploads/Data/UK-postcode-boundaries-Jan-2015.zip",
"postal_shapefile"
)
unzip("postal_shapefile")
uk <- read_sf('Distribution/Sectors.shp')
region.scores <- data.frame(stringsAsFactors = FALSE,
NAME_3 = c("BB7","BB1","PR5","CA3",
"DG12","CA15","CW1","ST7","CW9","PR4","PR2","PR7",
"ST17","ST18","ST16","ST3","ST4","TF9"),
Score = c(0.717647058823529,
0.761194029850746,0.4375,0.777777777777778,0.764705882352941,
0.727272727272727,0.807017543859649,0.830769230769231,
0.868421052631579,0.819672131147541,0.732673267326733,
0.741379310344828,0.811764705882353,0.761194029850746,
0.844827586206897,0.68,0.855263157894737,0.857142857142857),
Shop = c("AAA","AAA","AAA","BBB",
"BBB","BBB","CCC","CCC","CCC","DDD","DDD","DDD",
"EEE","EEE","EEE","FFF","FFF","FFF"),
Cor1 = c(53.874,53.756,53.731,54.907,
54.99,54.712,53.103,53.088,53.259,53.754,53.778,
53.645,52.789,52.814,52.813,52.981,52.995,52.897),
Cor2 = c(-2.386,-2.462,-2.656,-2.939,
-3.251,-3.481,-2.434,-2.265,-2.501,-2.833,-2.708,
-2.652,-2.099,-2.081,-2.118,-2.122,-2.183,-2.469))
uk <- left_join(uk, region.scores, by = c('name'='NAME_3'))
uk
uk %>% filter(!is.na(Score))
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc) +
geom_sf(aes(fill = AREA))
ggplot() +
geom_sf(data = uk, alpha = 0.3) +
geom_sf(data = uk, aes(fill = Score)) +
scale_fill_gradient(low = "red", high = "green") +
labs(title = "Scores by region",
fill = "Scores") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, size = 20),
axis.title = element_blank(),
plot.background = element_blank(),
legend.position = c(0.10, 0.20),
plot.margin = margin(5, 0, 5, 0))
rs_sf <- st_as_sf(region.scores, coords=c('Cor2','Cor1'), crs=st_crs(uk))
ggshop <- ggplot()+
geom_sf(data=uk,mapping=aes(fill=Score),colour=NA) +
geom_sf(data=rs_sf,mapping=aes(shape=Shop))+
coord_sf(xlim=c(-4,-2),ylim=c(52.6,55.15))