我有一些沿海岸线的空间点数据,跨越多年。根据这个答案,我已经将这些点绘制出来,并使用控制透明度的滑块显示不同年份。
在使用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)