How do you arbitrarily create spatial data on a map using both ggvis and a mapping package (e.g. ggmap)

I have spatial points that are along the coastline, between years. Using the answer to this , I charted the points and used the opacity slider to show different years.

Is it currently possible to overlay a simple map when using ggvis, potentially using ggmap or any other mapping package?

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)
+4
source share
1 answer

A bit late, but mapview might be the solution for you (it was only released by CRAN a few days ago).

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.

+2

All Articles