suppressPackageStartupMessages({ library(PWFSLSmoke) library(ggplot2) }) setSpatialDataDir(params$spatialDataDir) ws_monitor <- params$ws_monitor
monitor_leaflet(ws_monitor)
# Get a bounding box that will include all monitor locations bbox <- RgoogleMaps::qbbox(ws_monitor$meta$latitude, ws_monitor$meta$longitude, margin = list(m = c(10,10,10,10), TYPE = "perc")) # Get the map image from esri basemap <- esriMap_getMap(bboxString = paste0(bbox$lonR[1], ",", bbox$latR[1], ",", bbox$lonR[2], ",", bbox$latR[2])) yearCount <- length(unique(lubridate::year(ws_monitor$data$datetime))) monthCount <-length(unique(lubridate::month(ws_monitor$data$datetime))) layout(matrix(1:((monthCount+1)*(yearCount+1)), monthCount+1, yearCount+1, byrow = FALSE), widths=c(.8,rep(4, yearCount)), heights = c(1,rep(4, monthCount+1))) par(mar = c(0,0,0,0)) plot.new() # Write the month names for( month in sort(unique(lubridate::month(ws_monitor$data$datetime))) ){ text <- month.name[month] plot(0,0,col="transparent", axes = F) text(0,0,text, srt = 90, cex = 1.5) } # Map monitors from every month in each year for ( year in sort(unique(lubridate::year(ws_monitor$data$datetime))) ){ plot(0,0,col="transparent", axes = F) text(0,0, as.character(year), cex = 2) for ( month in sort(unique(lubridate::month(ws_monitor$data$datetime))) ) { if ( month < 12 ) { tlim <- paste0(as.character(year), stringr::str_pad(as.character(c(month, month+1)), 2, side = 'left', "0"), '01') } else { tlim <- paste0(as.character(year), c("120100", "123123")) } monitor <- monitor_subset(ws_monitor, tlim = tlim) result <- try ( monitor_esriMap(monitor, mapRaster = basemap) ) if ("try-error" %in% class(result)) { esriMap_plotOnStaticMap(basemap) } box("figure", col = 'gray50') } }
counts2015 <- data.frame(time = ws_monitor$data$datetime, count = apply(ws_monitor$data[-1], 1, function(x) sum(!is.na(x)))) ggplot(counts2015, aes(time, count))+ geom_bar(stat="identity")+ labs(title='Number of valid data points by hour', subtitle='2015')
monitor_timeseriesPlot(ws_monitor, style='gnats', xlab = "", localTime = FALSE, ylim = c(0,1000))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.