# Lesson 16: Visualizing Data II - Errorbars and Ribbons

Lesson 16: Visualizing Data II - Errorbars and Ribbons## Overview

In this chapter we'll continue working on scatterplots, but we'll focus on several enhancements and manipulations that may be useful. Note that these are not specific to scatterplots, but we will demonstrate them in the context of scatterplots.

## Objectives

- Add errorbars to plots
- Draw arbitrary polygons on charts
- Use the function polygon() to show error ribbons
- Use errorbars or ellipses to show error in two dimensions
- Reverse axes on a plot

## R

The R code file and data files for this lesson can be found on the Essential R - Notes on learning R page.

# 16.1 - Errorbars - Introducing arrows()

16.1 - Errorbars - Introducing arrows()The function `arrows()`

can be used to draw arrows from one point to another, but by manipulating the arrow ends it can also create errorbars.

# 16.2 - Custom Axis Formatting

16.2 - Custom Axis FormattingOn occasion we may want to format an axis in units that are different from the units in the variable - in this example the units are days of the year (ordinal days), bu we want to label them with "Month Day" (e.g. "March 10"). Here we'll explore how `axis()`

can be used to do this.

# 16.3 - Plotting Errorbars and Preparing to Add Lines

16.3 - Plotting Errorbars and Preparing to Add LinesHere we're putting toghether what we've learned so far in this chapter by adding errorbars for groups of data points to our plot with custom axes. We'll also prepare to add the regression lines, but using `lines()`

rather than `abline()`

so as to confine our lines to the range of the predictor variable.

# 16.4 - Adding Lines and a Small Table to a Plot

16.4 - Adding Lines and a Small Table to a PlotHere we'll conclude this example by adding our lines and a small table that shows the p-values from an ANCOVA on the plot.

# 16.5 - Plotting Confidence Intervals - Preparing the Data

16.5 - Plotting Confidence Intervals - Preparing the DataIn the next example we'll use the function `polygon()`

to show the 95% confidence interval around the means of some values (Since we're not fitting a model here, so we can't use `predict()`

as we did previously). Here we'll examine the data an plan the plot.

# 16.6 - Introducing polygon() and Prepping Data for Ribbons

16.6 - Introducing polygon() and Prepping Data for RibbonsNow we'll introduce `polygon()`

, show how to use it to create a ribbon, and set up the vectors that we'll need for drawing our 95% CI ribbons.

# 16.7 - Polygons with Semi-Transparent Colors

16.7 - Polygons with Semi-Transparent ColorsNow we'll put all the pieces together to create a plot that shows both the means and 95% CI for the means for soil pH at different distances from the road in the two road treatments.

# 16.8 - Errorbars in 2 Dimensions & Ellipses

16.8 - Errorbars in 2 Dimensions & EllipsesIn this video we'll consider the use to 2-dimension error bars or ellipses to show error in 2 variables.

# 16.9 - Reversing Axes

16.9 - Reversing AxesWe'll return to our earlier discussion of custom axes and consider how we could set up a reversed axis plot.