Skip to content

Instantly share code, notes, and snippets.

@boshek
boshek / corrr_purrr_group.md
Last active October 11, 2017 23:48
Correlation Network Plots by Group with purrr, corrr and ggraph

Correlation Network Plots by Groups

Packages

To run this you will need the following packages:

library(corrr)
@boshek
boshek / Station_selection.R
Last active October 17, 2017 22:19
Find all current hydrometric stations then subset by NRD
library(tidyverse)
library(sf)
library(tidyhydat)
library(bcmaps)
## Say get Thompson District
nr_district_to <- st_as_sf(nr_districts) %>%
filter(REG_ORG_UN == "Thompson-Okanagan Natural Resource Region")
# Packages ----------------------------------------------------------------
library(sf)
library(dplyr)
library(tidyhydat)
library(readr)
library(ggplot2)
library(here)
library(raster)
@boshek
boshek / tidyhydat_col_names_eval.R
Last active August 14, 2018 14:38
A script to extract the column names for most tidyhydat functions
library(tidyverse)
# Functions ---------------------------------------------------------------
eval_funcs <- function(x){
cat(x,"\n")
if(grepl("hy_", x)){
return(names(eval(parse(text = paste0(x,"(hydat_path = hy_test_db())")))))
}
if(grepl("realtime_",x)){
title output
Simple SQL and dplyr
html_document
keep_md
true

Load Packages

library(gganimate)
library(ggplot2)
library(tidyhydat)
library(tidyverse)

Just do it with one station

@boshek
boshek / calculating_area_sf.md
Created September 19, 2018 21:23
Calculate Area with sf

Calculate Area with sf

library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
@boshek
boshek / rasterizing
Last active September 26, 2018 19:04
Comapring POSTGIS rasterization with fasterize
library(sf)
library(dplyr)
library(fasterize)
shape <- "MULTIPOLYGON (((1126095 1246073, 1126221 1246053, 1126358 1246059, 1126383 1245909, 1126457 1245800, 1126605 1245831, 1126756 1245812, 1126812 1245652, 1126805 1245526, 1126841 1245377, 1126859 1245227, 1126868 1245077, 1126881 1244927, 1126949 1244805, 1126954 1244667, 1126806 1244635, 1126658 1244602, 1126508 1244591, 1126358 1244591, 1126283 1244701, 1126248 1244825, 1126256 1244951, 1126219 1245100, 1126197 1245249, 1126175 1245374, 1126145 1245498, 1126114 1245622, 1126025 1245743, 1125919 1245839, 1125803 1245897, 1125638 1245928, 1125547 1246037, 1125693 1246143, 1125842 1246150, 1126095 1246073)))"
tictoc::tic()
## Actually connect to the database
@boshek
boshek / spinning_hydrograph.R
Created October 16, 2018 03:22
Animate a hydrograph in a circle
## based on this code: https://twitter.com/JustTheSpring/status/1049468485334523906
library(tidyverse)
library(lubridate)
library(gganimate)
library(tidyhydat)
stn <- "08MF005"
flow_data <- hy_daily_flows(stn, start_date = "2012-01-01", end_date = "2016-12-31") %>%
filter(!is.na(Value)) %>%
@boshek
boshek / notes.md
Last active January 10, 2019 23:09
Diagnosing bcmaps.rdata problem
> devtools::install_github("bcgov/bcmaps.rdata")
Downloading GitHub repo bcgov/bcmaps.rdata@master
   checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' ...
   checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' ...  
√  checking for file 'C:\Users\salbers\AppData\Local\Temp\RtmpMV207E\remotes2d70214a431b\bcgov-bcmaps.rdata-6f2f9cd/DESCRIPTION' (390ms)
-  preparing 'bcmaps.rdata': (11.9s) 
   checking DESCRIPTION meta-information ... 
   checking DESCRIPTION meta-information ...