USGS - science for a changing world

Additional Topics in R

Spatial Analyses

Date Handling

Dates can be in a few different formats: character, numeric, POSIXlt, and POSIXct * Blog post about character and numeric formats: http://www.r-bloggers.com/date-formats-in-r/ * Article about the Date class and POSIX classes (also has lots of useful examples): http://biostat.mc.vanderbilt.edu/wiki/pub/Main/ColeBeck/datestimes.pdf * Useful R package: lubridate, https://cran.r-project.org/web/packages/lubridate/lubridate.pdf * Article describing date classes, the R packages chron and lubridate, and small intro to plotting with dates: http://www.noamross.net/blog/2014/2/10/using-times-and-dates-in-r---presentation-code.html

Matrices

Trend Decomposition

Handling/Exporting Output

  • For tabular data, format it as a data frame. Then use the write.csv or write.table functions to export it
  • For exporting plots, there is a button in the plots tab in RStudio called “Export”. For in-line exporting of plots, you can save it in many formats using these functions: jpeg(), png(), pdf(), svg(), postscript()

ggplot2

Rmarkdown

Creating dynamic PDFs, word documents, or HTMLs. A place to have code and text all in one document. * Basic introduction to what R Markdown really is and how to apply it: http://rmarkdown.rstudio.com/ * USGS uses R Markdown (NWIS Reporting Application - release date sometime in 2016)!! * Cheatsheet for R Markdown: https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf

Other

Lindsay R. Carr