欢迎光临散文网 会员登陆 & 注册

R语言空间可视化:绘制英国脱欧投票地图

2021-04-02 09:22 作者:拓端tecdat  | 我要投稿

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

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

  1. library(sp)

  2. library(raster)

  3. download.file("http://biogeo.ucdavis.edu/data/gadm2.8/rds/GBR_adm2.rds","GBR_adm2.rds")

  4. UK=readRDS("GBR_adm2.rds")

  5. UK@data[159,"HASC_2"]="GB.NR"

  6. plot(UK, xlim = c(-4,-2), ylim = c(50, 59), main="UK areas")

添加爱尔兰

 


  1. plot(IRL,add=TRUE)

 

 添加法国,它位于右下方,因此我们应该看到一点…


  1. plot(FR,add=TRUE)

 

 

然后,我们可以检索英国退欧公投数据


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

我们可以发现,脱欧赢得了51.89%的选票

  1. > sum(referendum$Leave)/(sum(referendum$Leave)+sum(referendum$Remain))

  2. [1] 0.5189184

大家可以看一下,使用


  1. plot(UK, col = map_data$Brexit, border = "gray1", xlim = c(-4,-2), ylim = c(50, 59), main="How the UK has voted?", bg="#A6CAE0")

  2. plot(IRL, col = "lightgrey", border = "gray1",add=TRUE)

  3. plot(FR, col = "lightgrey", border = "gray1",add=TRUE)

(我们添加了一个小图例以使其更清晰)。为此,我们可以使用制图软件包

  1. plot(UK, col = "grey", border = "gray1", xlim = c(-4,-2), ylim = c(50, 59),bg="#A6CAE0")

  2. plot(IRL, col = "lightgrey", border = "gray1",add=TRUE)

  3. plot(FR, col = "lightgrey", border = "gray1",add=TRUE)

  4. choroLayer(spdf = UK,

  5. df = map_data,

  6. var = "Percentage_Remain",

  7. breaks = seq(0,100,10),

  8. col = cols,

  9. legend.pos = "topright",

  10. legend.title.txt = "",

  11. legend.values.rnd = 2,

  12. add = TRUE)

 


R语言空间可视化:绘制英国脱欧投票地图的评论 (共 条)

分享到微博请遵守国家法律