R語言空間可視化:繪制英國脫歐投票地圖
原文鏈接:http://tecdat.cn/?p=13247
本文我們繪制英國脫歐投票的地圖。第一步是繪制底圖
library(sp)
library(raster)
download.file("http://biogeo.ucdavis.edu/data/gadm2.8/rds/GBR_adm2.rds","GBR_adm2.rds")
UK=readRDS("GBR_adm2.rds")
UK@data[159,"HASC_2"]="GB.NR"
plot(UK, xlim = c(-4,-2), ylim = c(50, 59), main="UK areas")

添加愛爾蘭
?
plot(IRL,add=TRUE)

?
?添加法國,它位于右下方,因此我們應(yīng)該看到一點(diǎn)…
plot(FR,add=TRUE)

?
?
然后,我們可以檢索英國退歐公投數(shù)據(jù)
referendum=ddply(referendum,.(Region,HASC_code),summarise,Remain=sum(Remain),Leave=sum(Leave))
我們可以發(fā)現(xiàn),脫歐贏得了51.89%的選票
> sum(referendum$Leave)/(sum(referendum$Leave)+sum(referendum$Remain))
[1] 0.5189184
大家可以看一下,使用
plot(UK, col = map_data$Brexit, border = "gray1", xlim = c(-4,-2), ylim = c(50, 59), main="How the UK has voted?", bg="#A6CAE0")
plot(IRL, col = "lightgrey", border = "gray1",add=TRUE)
plot(FR, col = "lightgrey", border = "gray1",add=TRUE)

(我們添加了一個小圖例以使其更清晰)。為此,我們可以使用制圖軟件包
plot(UK, col = "grey", border = "gray1", xlim = c(-4,-2), ylim = c(50, 59),bg="#A6CAE0")
plot(IRL, col = "lightgrey", border = "gray1",add=TRUE)
plot(FR, col = "lightgrey", border = "gray1",add=TRUE)
choroLayer(spdf = UK,
df = map_data,
var = "Percentage_Remain",
breaks = seq(0,100,10),
col = cols,
legend.pos = "topright",
legend.title.txt = "",
legend.values.rnd = 2,
add = TRUE)

?