关于算法:拓端tecdatR语言空间可视化绘制英国脱欧投票地图

6次阅读

共计 934 个字符,预计需要花费 3 分钟才能阅读完成。

原文链接:http://tecdat.cn/?p=13247


本文咱们绘制英国脱欧投票的地图。第一步是绘制底图

UK@data\[159,"HASC_2"\]="GB.NR"
plot(UK, xlim = c(-4,-2), ylim = c(50, 59), main="UK areas")

增加爱尔兰

plot(IRL,add=TRUE)

 增加法国,它位于右下方,因而咱们应该看到一点…

plot(FR,add=TRUE)

而后,咱们能够检索英国退欧公投数据

referendum=ddply(referendum,.(Region,HASC_code),summarise,Remain=sum(Remain),Leave=sum(Leave))

咱们能够发现,脱欧博得了 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(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)

正文完
 0