使用传单和 xts 在 R 中制作动画地图 [英] Animate map in R with leaflet and xts
本文介绍了使用传单和 xts 在 R 中制作动画地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 R 中构建一个带有时间光标的动画地图.
I would like to build an animated map with a time cursor in R.
我有想要在地图上表示的时间序列 (xts).
I have time series (xts) that I would like to represent on map.
library(xts)
library(leaflet)
date<-seq(as.POSIXct("2015-01-01"), as.POSIXct("2015-01-10"), by=86400)
a<-xts(1:10,order.by=date)
b<-xts(5:14,order.by=date)
df = data.frame(Lat = 1:10, Long = rnorm(10),Id=letters[1:10])
leaflet() %>% addCircles(data = df,popup =df$Id)
#popup =paste(df$Id, xts value) time cursor on the map
有没有办法用传单包做到这一点?我还没有尝试 rmaps 包.
Is there a way to do this with the leaflet package? I didn't try rmaps package yet.
谢谢
https://github.com/skeate/Leaflet.timeline
推荐答案
有一个简单的例子
图书馆:
library(shiny)
library(xts)
library(leaflet)
library(dplyr)
数据:
date<-seq(as.Date("2015-01-01"), as.Date("2015-01-10"), by="day")
a<-xts(1:10,order.by=date)
df = data.frame(Lat = rnorm(1)+10, Long = rnorm(1),Id=a)
data_a<-data.frame(a)
data_a1<-data_a %>%
mutate("Lat" =as.numeric(df[1,1]),"Long"=as.numeric(df[2,1]),"Date"=rownames(data_a))
闪亮应用:
ui <- fluidPage(
sliderInput("time", "date",min(date),
max(date),
value = max(date),
step=1,
animate=T),
leafletOutput("mymap")
)
server <- function(input, output, session) {
points <- reactive({
data_a1 %>%
filter(Date==input$time)
})
output$mymap <- renderLeaflet({
leaflet() %>%
addMarkers(data = points(),popup=as.character(points()$a))
})
}
shinyApp(ui, server)
这篇关于使用传单和 xts 在 R 中制作动画地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文