Learn R Programming

rnoaa (version 0.1.0)

noaa_plot: Plot NOAA climate data.

Description

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

Usage

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

## S3 method for class 'noaa_data': noaa_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 noaa 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
# Search for data first, then plot
out <- noaa(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP',
startdate = '2010-05-01', enddate = '2010-10-31', limit=500)
noaa_plot(out)
noaa_plot(out, breaks="14 days")
noaa_plot(out, breaks="1 month", dateformat="%d/%m")
noaa_plot(out, breaks="1 month", dateformat="%d/%m")

out2 <- noaa(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP',
startdate = '2010-05-01', enddate = '2010-05-03', limit=100)
noaa_plot(out2, breaks="6 hours", dateformat="%H")

# Combine many calls to noaa function
out1 <- noaa(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP',
startdate = '2010-03-01', enddate = '2010-05-31', limit=500)
out2 <- noaa(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP',
startdate = '2010-09-01', enddate = '2010-10-31', limit=500)
df <- noaa_combine(out1, out2)
noaa_plot(df)
## or pass in each element separately
noaa_plot(out1, out2, breaks="45 days")

Run the code above in your browser using DataLab