【问题标题】:How do you plot spatial data interactively on a map using both ggvis and a mapping package (ie. ggmap)如何使用 ggvis 和映射包(即 ggmap)在地图上交互地绘制空间数据
【发布时间】:2014-11-06 03:21:11
【问题描述】:

我有沿海岸线的空间点,在几年之间。使用this 的答案,我绘制了这些点并使用了一个控制不透明度的滑块来显示不同的年份。

目前是否可以在使用 ggvis 时覆盖简单地图,可能使用 ggmap 或任何其他映射包?

library(ggmap)
library(ggvis)

#simple dataset
long <- c(-53.53167, -53.53167, -53.68000, -53.64667, -53.68500)
lat <- c(47.16833, 47.18500, 47.01167, 47.00500, 47.98833)
year <- c(1995:1999)
count <- rpois(5, 20)
data1 <- as.data.frame(cbind(year, count, lat, long))

#interactive data visual, with the goal of having a map in the background
data %>% 
  ggvis(~long, ~lat, size=~count) %>% 
  layer_points(opacity=input_slider(min(data$year), max(data$year),     step=1,map=function(x) ifelse(data$year == x, 1, 0)))

#in ggmap, an example of a potential map to make interactive
mylocation <- c(min(long), min(lat))
mymap <- get_map(location=mylocation, source="google", maptype="roadmap", zoom = 8)
ggmap(mymap) + geom_point(data=data1, aes(x=long, y=lat, size=count), alpha=0.6)

【问题讨论】:

  • 如果我没记错的话,ggvis 还不能处理地图。

标签: r map ggmap ggvis


【解决方案1】:

有点晚了,但mapview 可能是您的解决方案(几天前才发布到 CRAN)。

library(ggmap)
library(ggvis)
library(sp)
library(mapview)

#simple dataset
long <- c(-53.53167, -53.53167, -53.68000, -53.64667, -53.68500)
lat <- c(47.16833, 47.18500, 47.01167, 47.00500, 47.98833)
year <- c(1995:1999)
count <- rpois(5, 20)

# convert to SpatialPointsDataFrame
data1 <- as.data.frame(cbind(year, count, lat, long))
proj4string(data1) <- CRS("+init=epsg:4326")

# view it
mapview(data1)

这不提供时间滑块等,但会在每个点提供属性的弹出窗口,因此可以通过这种方式检索年份。对于带有时间滑块的解决方案,您可以使用 mapview 构建一个闪亮的应用程序。

干杯 蒂姆

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 2021-03-19
    • 1970-01-01
    • 2021-06-06
    相关资源
    最近更新 更多