我一直在使用这两个指南来制作R闪亮的时间尺度等值线图,我对此很新。
http://journocode.com/2016/01/28/your-first-choropleth-map/
https://rpubs.com/walkerke/leaflet_choropleth
在第一个示例中,使用表示年份的两个单独的csv创建时间刻度。是否可以使用一个csv与一个代表年(2009-2016)的列?例如,一个县多边形可能看起来像"变量"作为年份,"价值"是等值时间所显示的价值观:
head(merge)
CDNAME id variable value CDUID CDTYPE PRUID PRNAME
1 Algoma 1 2016 1 3557 DIS 35 Ontario
2 Algoma 99 2014 3 3557 DIS 35 Ontario
3 Algoma 197 2012 0 3557 DIS 35 Ontario
4 Algoma 246 2011 2 3557 DIS 35 Ontario
5 Algoma 344 2009 3 3557 DIS 35 Ontario
6 Algoma 50 2015 3 3557 DIS 35 Ontario
我的示例代码如下链接#2:
library(shiny)
library(rgdal)
library(leaflet)
library(plyr)
onC <- readOGR("C:\\Users\\app\\data", layer="OntarioCounties", encoding="utf-8" )
timeseries <- read.csv("timeseries.csv", header=TRUE, stringsAsFactors = FALSE)
names(timeseries) <- sub('CountyList', 'CDNAME', names(timeseries))
merge <- sp::merge(timeseries,onC, by="CDNAME", duplicateGeoms=TRUE)
palette <- colorBin(c('#fee0d2', #an example color scheme. you can substitute your own colors
'#fcbba1',
'#fc9272',
'#fb6a4a',
'#ef3b2c',
'#cb181d',
'#a50f15',
'#67000d'),
bins = c(0, 5, 8, 10, 12, 14, 18, 24, 32))
state_popup <- paste0("<strong>County: </strong>",
merge$CDNAME,
"</br><strong> Year: </strong>",
merge$variable,
"</br><strong> # of Projects funded: </strong>",
merge$value)
mymap<-leaflet(data = onC) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor= palette(merge$value),
fillOpacity = 0.8,
color = "#BDBDC3",
weight = 1 ,
popup = state_popup)