Introduction to Working With Time Series Data in Text Formats in R feature image Source: National Ecological Observatory Network (NEON)
NEON EDUCATION bio photo

NEON EDUCATION

Devoted to open data and open source in science and education.

View All Tutorials

Tags

R programming (52)
Hierarchical Data Formats (HDF5) (11)
Spatial Data & GIS (22)
LiDAR (7)
Raster Data (11)
Remote Sensing (11)
Data Visualization (4)
Hyperspectral Remote Sensing (7)
Time Series (15)
Phenology (7)
Vector Data (6)
Metadata (1)
Git & GitHub (6)
(1) (1)

Tutorial by R Package

dplyr (7)
ggplot2 (16)
h5py (2)
lubridate (time series) (6)
maps (1)
maptools (1)
plyr (2)
raster (26)
rasterVis (raster time series) (3)
rgdal (GIS) (24)
rgeos (2)
rhdf5 (11)
sp (5)
scales (4)
gridExtra (4)
ggtheme (0)
grid (2)
reshape2 (3)
plotly (5)

View ALL Tutorial Series




Twitter Youtube Github


Blog.Roll

R Bloggers

Series: Introduction to Working With Time Series Data in Text Formats in R

About

The tutorials in this series cover how to open, work with and plot tabular time-series data in R. Additional topics include working with time and date classes (e.g., POSIXct, POSIXlt, and Date), subsetting time series data by date and time and created facetted or tiles sets of plots.

Data used in this series cover NEON Harvard Forest Field Site and are in .csv file format.

R Skill Level: Intermediate - you’ve got the basics of R down but haven’t previously worked with time-series data in R.

Series Goals / Objectives

After completing the series you will:

  • Time Series 00
    • Be able to open a .csv file in R using read.csv()and understand why we are using that file type.
    • Understand how to work data stored in different columns within a data.frame in R.
    • Understand how to examine R object structures and data classes.
    • Be able to convert dates, stored as a character class, into an R date class.
    • Know how to create a quick plot of a time-series data set using qplot.
  • Time Series 01
    • Know how to import a .csv file and examine the structure of the related R object.
    • Use a metadata file to better understand the content of a dataset.
    • Understand the importance of including metadata details in your R script.
    • Know what an EML file is.
  • Time Series 02
    • Understand various date-time classes and data structure in R.
    • Understand what POSIXct and POSIXlt data classes are and why POSIXct may be preferred for some tasks.
    • Be able to convert a column containing date-time information in character format to a date-time R class.
    • Be able to convert a date-time column to different date-time classes.
    • Learn how to write out a date-time class object in different ways (month-day, month-day-year, etc).
  • Time Series 03
    • Be able to subset data by date.
    • Know how to search for NA or missing data values.
    • Understand different possibilities on how to deal with missing data.
  • Time Series 04
    • Know several ways to manipulate data using functions in the dplyr package in R.
    • Be able to use group-by(), summarize(), and mutate() functions.
    • Write and understand R code with pipes for cleaner, efficient coding.
    • Use the year() function from the lubridate package to extract year from a date-time class variable.
  • Time Series 05
    • Be able to create basic time series plots using ggplot() in R.
    • Understand the syntax of ggplot() and know how to find out more about the package.
    • Be able to plot data using scatter and bar plots.
  • Time Series 06
    • Know how to use facets() in the ggplot2 package.
    • Be able to combine different types of data into one plot layout.
  • Time Series Culmination Activity
    • have applied ggplot2 and dplyr skills to a new data set.
    • learn how to set min/max axis values in ggplot() to align data on multiple plots.

Things You’ll Need To Complete This Series

Setup RStudio

To complete the tutorial series you will need an updated version of R and, preferably, RStudio installed on your computer.

R is a programming language that specializes in statistical computing. It is a powerful tool for exploratory data analysis. To interact with R, we strongly recommend RStudio, an interactive development environment (IDE).

Install R Packages

You can chose to install packages with each lesson or you can download all of the necessary R packages now.

  • ggplot2: install.packages("ggplot2")
  • lubridate: install.packages("lubridate")
  • dplyr: install.packages("dplyr")
  • scales: install.packages("scales")
  • gridExtra: install.packages("gridExtra")
  • ggthemes: install.packages("ggthemes")
  • reshape2: install.packages("reshape2")
  • zoo: install.packages("zoo")

More on Packages in R - Adapted from Software Carpentry.

Download Data

Download NEON Teaching Data Subset: Meteorological Data for Harvard Forest

The data used in this lesson were collected at the National Ecological Observatory Network’s Harvard Forest field site. These data are proxy data for what will be available for 30 years on the NEON data portal for the Harvard Forest and other field sites located across the United States.


Set Working Directory: This lesson assumes that you have set your working directory to the location of the downloaded and unzipped data subsets. An overview of setting the working directory in R can be found here.

R Script & Challenge Code: NEON data lessons often contain challenges that reinforce learned skills. If available, the code for challenge solutions is found in the downloadable R script of the entire lesson, available in the footer of each lesson page.

Working with Spatio-temporal Data in R Series: This tutorial series is part of a larger spatio-temporal tutorial series and Data Carpentry workshop. Included series are introduction to spatio-temporal data and data management, working With raster data in R, working with vector data in R and working with tabular time series in R.

Tutorials in the Series