# Creating a Plot with TERR and dygraphs

If you have time and date data, you can create a line plot showing trends with the TERR-compatible, JavaScript-enabled dygraphs package.

## About this task

Perform this task from the TERR console. This example walks you through creating a line plot with data available on the internet, and then displays the results in a browser.

For information about the packages used in this example task, see the following links.

Package link | Package short description
--- | ---
http://www.quantmod.com/ | The quantmod package provides quantitative modeling functions.
http://dygraphs.com/ | The dygraphs package provides fast, flexible JavaScript charting functions.

Note: You can perform this task from RStudio using the TERR engine. If you use RStudio, the results are displayed in the RStudio Viewer pane.

## Before you begin

TERR, access to the internet, and a browser.

## Procedure

1. From the TERR console, install the quantmod and dygraphs packages.

       install.packages(c("quantmod", "dygraphs"))

   TERR checks TRAN and then CRAN for the packages to install, and then installs them along with any packages they require.
2. Load the quantmod package.

       library("quantmod")

   The package and its required packages are loaded, and messages about any object masking are displayed, along with any warnings regarding TERR differences.
3. Call the quantmod function `getSymbols` to load the data and specify the source.

       getSymbols("ATLA013URN", src = "FRED", auto.assign=FALSE)

   In this case, the data is the Unemployment Rate in Atlanta-Sandy Springs-Roswell, GA. The source is the Federal Reserve Economic Data.
   Tip: To see more information about `getSymbols` (for example, other supported data sources and other arguments), see its help file in the quantmod package help.
   A message about the function is displayed and the data object is loaded.
4. Load the dygraphs package.

       library("dygraphs")

   The package and its required packages are loaded, and messages about any object masking are displayed, along with any warnings regarding TERR differences.
5. Call the `dygraph` function as follows to plot the data and display a plot title.

       dygraph(ATLA013URN, main = "Atlanta area unemployment")

## Results

The default browser is launched, and a line plot showing the Atlanta area unemployment rate from January 1990 through January 2016 is displayed.

- You can resize the image. The X-axis label detail adjusts to the window size.
- You can highlight individual points on the line by hovering over the line with your mouse or pointer device. The row value for the highlighted point (in this case, the month and year, data source, and Y-axis value) is shown in the upper left of the browser window.