knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE, cache = TRUE )
rnoaa
is an R wrapper for many NOAA data types, including National Climatic Data Center (NCDC).
library('rnoaa') library('plyr')
ncdc_stations(datasetid='GHCND', locationid='FIPS:12017', stationid='GHCND:USC00084289')
out <- ncdc(datasetid='NORMAL_DLY', datatypeid='dly-tmax-normal', startdate = '2010-05-01', enddate = '2010-05-10') out$data
out <- ncdc(datasetid='NORMAL_DLY', stationid='GHCND:USW00014895', datatypeid='dly-tmax-normal', startdate = '2010-01-01', enddate = '2010-12-10', limit = 300) ncdc_plot(out)
Search for data first, then plot
out <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-05-01', enddate = '2010-10-31', limit=500)
Default plot
ncdc_plot(out)
Create 14 day breaks
ncdc_plot(out, breaks="14 days")
One month breaks
ncdc_plot(out, breaks="1 month", dateformat="%d/%m")
Search for data
out <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-05-01', enddate = '2010-10-31', limit=500)
Make a plot, with 6 hour breaks, and date format with only hour
ncdc_plot(out, breaks = "1 month", dateformat = "%d/%m")
Search for two sets of data
out1 <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-03-01', enddate = '2010-05-31', limit=500) out2 <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-09-01', enddate = '2010-10-31', limit=500)
Then combine with a call to ncdc_combine
df <- ncdc_combine(out1, out2) head(df[[1]]); tail(df[[1]])
Then plot - the default passing in the combined plot plots the data together. In this case it looks kind of weird since a straight line combines two distant dates.
ncdc_plot(df)
But we can pass in each separately, which uses facet_wrap
in ggplot2
to plot each set of data in its own panel.
ncdc_plot(out1, out2, breaks="45 days")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.