Skip to content

Instantly share code, notes, and snippets.

View djhocking's full-sized avatar

Daniel J. Hocking djhocking

View GitHub Profile
anonymous
anonymous / PRISMdownload.R
Created February 18, 2014 17:10
######################################################################################
# PROGRAM: download.prism
# USE: BATCH DOWNLOAD AND UNCOMPRESSION OF PRISM DAILY OR MONTHLY GRIDDED DATA
# PRISM URL: http://prism.nacse.org/
# REQUIRES: >= R 3.0, RCurl
#
# ARGUMENTS:
# data.type TYPE OF CLIMATE DATA ("ppt","tmin","tmax","tmean")
# date.range A VECTOR WITH START AND END DATA IN y/m/d FORMAT
# time.step DEFINES TIMESTEP OF PRODUCT ("daily"/"monthly")
@anarosner
anarosner / purl_wrapper_demo
Last active August 29, 2015 14:07
purl and wrapper script demo
#purling is in the knitr package
library(knitr)
setwd("C:/ALR/Models/boo") #example using local windows directory, can easily switch
#it can be really simple
purl( "script1.Rmd", "script1.R" )
#just specify the rmd filename, then r filename, with extensions
@djhocking
djhocking / gist:eff1072b54b6d8049270
Last active August 29, 2015 14:13
Big Queries and collect with dplyr
# fetch temperature data
tbl_values <- left_join(tbl_series,
select(tbl_variables, variable_id, variable_name),
by=c('variable_id'='variable_id')) %>%
select(-file_id) %>%
filter(location_id %in% df_locations$location_id,
variable_name=="TEMP") %>%
left_join(tbl_values,
by=c('series_id'='series_id')) %>%
left_join(select(tbl_locations, location_id, location_name, latitude, longitude, featureid=catchment_id),
@tmalsburg
tmalsburg / predict_vs_simulate.org
Last active November 18, 2022 01:14
Predict vs simulate in lme4

Predict vs simulate in lme4

For this investigation we are going to use the sleepdata data set from the lme4 package. Here is the head of the data frame:

@djhocking
djhocking / ggplot boxplot continuous x with groups
Last active February 12, 2016 20:58
Trying to make a boxplot with ggplot2 in R where the x-axis in continous but their are paired boxplots for each value of on the x-axis based on another factor
# ggplot boxplot groups of continuous x
### Daniel J. Hocking
I am trying to make a boxplot with ggplot2 in R where the x-axis in continous but their are paired boxplots for each value of on the x-axis based on another factor with two possible values. I want to make a plot where boxplots are arranged by number of survey years on the x-axis but paired by spatialTF (2 boxplots for every value of n_years) but n_years are not evenly spaced.
This plot gets the paired boxplots correct by year but the years on the x-axis are evenly spaced and don't reflect the actual (continuous) time between years.
```
ggplot(df_converged, aes(factor(n_years), mean_N_est)) +