r - 使用传单和 xts 在 R 中动画 map

标签 r leaflet xts

我想用 R 中的时间光标构建一个动画 map 。

我有我想在 map 上表示的时间序列 (xts)。

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 包。

谢谢

编辑: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))

Shiny 应用:
 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)

关于r - 使用传单和 xts 在 R 中动画 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30370840/

相关文章:

r - 如何通过获取先前的值来增加 xts 对象中的观察数量?

r - 将日期从 MySQL 正确导入到 R

r - 将变量中的值设置为 NA,以另一个变量为条件

leaflet - 如何在 dc.leaflet.js 中显示值(总和)而不是标记计数

r - 传单中的 map 标记 Shiny

r - XTS 指数和交易日问题

r - 通过使用 .$ 和 .[ ] 调用值来执行计算

r - 设置 R bookdown 输入目录

javascript - 为传单问题添加标记

R: Apply.yearly sums 从 1 月不包括在内到次年的 1 月包括在内。我怎样才能使它从 12 月到 12 月总和?