rnoaa (version 0.2.0)

ncdc_plot: Plot NOAA climate data.

Description

This function accepts directly output from the ncdc function, not other functions.

Usage

ncdc_plot(..., breaks = "7 days", dateformat = "%d/%m/%y")

# S3 method for ncdc_data ncdc_plot(..., breaks = "7 days", dateformat = "%d/%m/%y")

Arguments

...
Input noaa object or objects.
breaks
Regularly spaced date breaks for x-axis. See date_breaks
dateformat
Date format using standard POSIX specification for labels on x-axis. See date_format

Value

Plot of climate data.

Details

This is a simple wrapper function around some ggplot2 code. There is indeed a lot you can modify in your plots, so this function just does some basic stuff. Here's the code within this function, where input is the output from a ncdc call - go crazy: input <- input$data input$date <- ymd(str_replace(as.character(input$date), "T00:00:00\.000", '')) ggplot(input, aes(date, value)) + theme_bw(base_size=18) + geom_line(size=2) + scale_x_datetime(breaks = date_breaks("7 days"), labels = date_format(' labs(y=as.character(input[1,'dataType']), x="Date")

Examples

Run this code
## Not run: ------------------------------------
# # 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)
# ncdc_plot(out)
# ncdc_plot(out, breaks="14 days")
# ncdc_plot(out, breaks="1 month", dateformat="%d/%m")
# ncdc_plot(out, breaks="1 month", dateformat="%d/%m")
# 
# out2 <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP',
# startdate = '2010-05-01', enddate = '2010-05-03', limit=100)
# ncdc_plot(out2, breaks="6 hours", dateformat="%H")
# 
# # Combine many calls to ncdc function
# 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)
# df <- ncdc_combine(out1, out2)
# ncdc_plot(df)
# ## or pass in each element separately
# ncdc_plot(out1, out2, breaks="45 days")
## ---------------------------------------------

Run the code above in your browser using DataCamp Workspace