Courtesy: mapview Popups

This document was produced on Mon Aug 27 2018 using mapview version 2.4.0


mapview provides a few convenience functions for popup creation. These popups can be used with both mapview and leaflet.


library(tidyverse)
library(mapview)
library(sp)

Load stations

pnt <- read_csv("Station_Champlain.csv") %>% 
  mutate(NAME = paste0("0", NAME))

Load hydrographs

somehow local images cannot be popuped by mapview

pnt <- pnt %>% 
  mutate(fil = paste0("../Hydrograph/Champlain_hydrograph_comp_", NAME, ".png"),
         Avail = if_else(file.exists(fil), T, F)) %>% 
  filter(Avail == T) %>% 
  select(-fil)

img <- paste0("http://www-personal.umich.edu/~cxiao/Champlain_Hydrograph/Champlain_hydrograph_comp_", 
              pnt$NAME, ".png")

Conert to spatialpoints

coordinates(pnt) <- ~ LON + LAT
proj4string(pnt) <- "+init=epsg:4326"

Add the Great Lakes watershed polygon

library(rgdal)
rBasin       <- readOGR(dsn = "LC_polygons", layer = "lake_champlain_basin_simplified")
## OGR data source with driver: ESRI Shapefile 
## Source: "P:\ipemf\wrf\Champlain\RMD\LC_polygons", layer: "lake_champlain_basin_simplified"
## with 1 features
## It has 19 fields
## Integer64 fields read as strings:  GNIS_ID InPoly_FID vertices
rBasin.proj  <- spTransform(rBasin, CRSobj = CRS(proj4string(pnt)))

rLake        <- readOGR(dsn = "LC_polygons", layer = "lake_champlain_simplified")
## OGR data source with driver: ESRI Shapefile 
## Source: "P:\ipemf\wrf\Champlain\RMD\LC_polygons", layer: "lake_champlain_simplified"
## with 1 features
## It has 24 fields
## Integer64 fields read as strings:  Resolution FType FCode Visibility InPoly_FID vertices
rLake.proj   <- spTransform(rLake, CRSobj = CRS(proj4string(pnt)))

Add hydrographs to the map

mapview(pnt, 
        label = pnt$NAME, layer.name = "Hydrographs", 
        popup = popupImage(img, src = "remote"), 
        cex = 5) +
  mapview(rBasin.proj, layer.name = "Basin", fill = F) +
  mapview(rLake.proj, layer.name = "Lake", fill = F)

Add cross-correlation plots to the map

## Correlation Table
rcor <- read_csv("../Stream-2011/Corr.May2011.csv") %>% 
  select(site_no, rCaPA)
## Cross-correlation plots
plt <- paste0("http://www-personal.umich.edu/~cxiao/Corr/May2011.models.", 
              rcor$site_no, ".png")
## gages infor
stn <- read_csv("Station_Champlain.csv") %>% 
  mutate(NAME = paste0("0", NAME)) %>% 
  right_join(rcor, by = c("NAME" = "site_no"))

coordinates(stn) <- ~ LON + LAT
proj4string(stn) <- "+init=epsg:4326"

mapview(stn, 
        label = paste0(stn$NAME, ", r=" ,stn$rCaPA), 
        layer.name = "Correlation", 
        popup = popupImage(plt, src = "remote"), 
        cex = 5 * stn$rCaPA) +
  mapview(rBasin.proj, layer.name = "Basin", fill = F) +
  mapview(rLake.proj, layer.name = "Lake", fill = F)

Hydrographs at the channel network points close to the lake

stn <- read_csv("Link.infor.csv")

coordinates(stn) <- ~ longitude + latitude
proj4string(stn) <- "+init=epsg:4326"

plt <- paste0("http://www-personal.umich.edu/~cxiao/Champlain_Hydrograph/Champlain_hydrograph_comp_", 
              stn$link5, ".Link.png")

mapview(stn, 
        label = paste0(stn$link5), 
        layer.name = "Hydrograph", 
        popup = popupImage(plt, src = "remote"), 
        cex = 5) +
  mapview(rBasin.proj, layer.name = "Basin", fill = F) +
  mapview(rLake.proj, layer.name = "Lake", fill = F)










### TBD