我正在根据过去 2.5 年中“英国退欧”一词的谷歌搜索引擎流量为我正在开展的项目制作交互式地图。我在格式化我的数据方面取得了很好的进展,并且一直在关注这个在线教程来帮助我,因为我是 datamaps 包的新手: http ://rmaps.github.io/blog/posts/animated-choropleths/
但是,我终其一生都无法弄清楚如何将列表中的数据与数据图合并,以正确生成如教程中所示的彩色等值线。我的地图看起来只是黑色。我的数据可以从这里下载: https ://drive.google.com/open?id=1xBqApmzAzzYHwDIEuxYiksO5bw5N7EBp
我目前拥有的代码如下:
#Packages for install.
install.packages("reshape2")
install.packages("Quandl")
install.packages("plyr")
install.packages("rMaps")
install.packages("datamaps")
install.packages("rgdal")
install.packages("kableExtra")
install.packages("funModeling")
install.packages("discretization")
install.packages("sf")
install.packages("maptools")
install.packages("RColorBrewer")
#Packages for run.
library(reshape2)
library(Quandl)
library(plyr)
library(rCharts)
library(rMaps)
library(datamaps)
library(kableExtra)
library(funModeling)
library(discretization)
library(rgdal)
library(sf)
library(maptools)
library(RColorBrewer)
#Find Brexit data set.Obvisouly set your own WD here.
Brexit.Data <- read.csv("E:/MSc Disso/Transposed Brexit.csv", check.names = FALSE)
#Melt Brexit data set.
datm <- melt(Brexit.Data, 'Year',
variable.name = 'Country',
value.name = 'Search Frequency',
check.names = FALSE
)
#Add breaks to data.
datm2 <- transform(datm,
fillKey = cut(datm[,3],breaks = c(-Inf,0,9,19,49,Inf),labels = c("0","1-9","10-19","20-49","50+"))
)
#Define CB pallet.
fills = setNames(
c(RColorBrewer::brewer.pal(5, 'PuBu'),'white'),
c(c("0","1-9","10-19","20-49","50+"))
)
#Payload creation for data maps.
datm3 <- dlply(na.omit(datm2), "Year", function(x){
y= toJSONArray2 (x, json = F)
names(y) = lapply(y, '[[', 'Country')
return(y)
})
datm3
#Data maps.
options(rCharts.cdn = TRUE)
map1 <- Datamaps$new()
map1$set(
dom = 'chart_1',
scope = 'world',
fills = fills,
data = datm3[[1]],
legend = TRUE,
labels = FALSE
)
map1
问题似乎是数据未与地图正确绑定。对此或替代方法的任何帮助将不胜感激。谢谢,乔