---
title: "Moving Time Part I" 
author: J. Hathaway
params:
  day: 17
  ptitle: true
  pbackground: true
  dtype: "none"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

if (params$day %% 2 == 0) md_intro_format <- "even_intro_format.Rmd"
if (params$day %% 2 == 1) md_intro_format <- "odd_intro_format.Rmd"

```

# [Questions about lubridate](day_15.html#/date-and-times) {data-background=#e8d725}


# R-Studio Connect and Interaction {data-background=#e8d725}

## Setting up R-Studio

Time to set up our R-Studio to share interactive documents.

>- https://shiny.byui.edu in R-Studio

Viewing on the website.

>- view with shiny.byui.edu


## Example: library(DT) - DataTables

Make a new Rmd file that just has the following in it (including the default yaml). 

```{r bob, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r bob2, eval=FALSE}
library(DT)
datatable(iris)
```

Putting information in your file [My interactive](https://shiny.byui.edu/connect/#/apps/3/access)

```{r child=md_intro_format}

```

## Try: library(DT) - DataTables

Look at the [DT: An R interface to the DataTables library](http://rstudio.github.io/DT/) website and find one or two modifications that you could make to your table output to move beyond the default.

> * Work as a table and push one file to R-Studio connect.
> * Make sure everyone at the table has the code saved on their computers.


```{r bob55, eval=FALSE, echo=TRUE}
library(DT)
datatable(iris)
```



# Being Readings {data-background=#e8d725}

## The development diagram

![](../images/visualization_diagram.png)

## Improving literacy

> - How do we improve literacy?
> - Show the graphic narrative example.

# Time Series Data {data-background=#e8d725}

## Are we using timetk?

Looks like the task doesn't require it.  I wanted you guys to see this package and understand the potential if you need it in the future - [Link](https://business-science.github.io/timetk/).

> * [Fun Forecasting Example](https://business-science.github.io/timetk/articles/TK03_Forecasting_Using_Time_Series_Signature.html)

## tibles, ts, xts, and zoos oh my!

**Use the links on this page to try and describe what ts, xts, and zoo formats are in R?**

We are not going to take the time to get into the weeds of xt, xts, zoo.  Here are two locations where you can read till your heart is content - [1](https://faculty.washington.edu/ezivot/econ424/Working%20with%20Time%20Series%20Data%20in%20R.pdf), and [2](https://www.datacamp.com/courses/manipulating-time-series-data-in-r-with-xts-zoo).


> - [What is the difference in zoo, xts, and ts objects?](https://stackoverflow.com/questions/33714660/what-is-the-difference-the-zoo-object-and-ts-object-in-r)
> - [Why xts?](http://joshuaulrich.github.io/xts/xts_faq.html)


## Really matrix formats

**Q: Why is xts implemented as a matrix rather than a data frame?**

xts uses a matrix rather than data.frame because: 1) xts is a subclass of zoo, and that's how zoo objects are structured; and 2) matrix objects have much better performance than data.frames.

## Why xts?

**Q: Why should I use xts rather than zoo or another time-series package?**

The main benefit of xts is its seamless compatibility with other packages using different time-series classes (timeSeries, zoo, .). In addition, xts allows the user to add custom attributes to any object. See the main xts vignette for more information.


<!-- ## tidyquant: One package to use them all (1). -->

<!-- Write out what this function is doing. -->

<!-- ```{r bofofokdfdkljf,eval=FALSE, echo=TRUE} -->
<!-- tq_transmute(select = adjusted, -->
<!--                mutate_fun = periodReturn,  -->
<!--                period = "daily", -->
<!--                type = "log") -->
<!-- ``` -->

<!-- - **Hint:** Read about `quantmod::periodReturn()` -->

<!-- ## tidyquant: One package to use them all (2). -->

<!-- Write out what this function is doing. -->

<!-- ```{r jfjfjjffjfjdk, eval=FALSE, echo=TRUE} -->
<!--   tq_portfolio(assets_col=symbol, -->
<!--                returns_col=daily.returns,  -->
<!--                weights = tibble(asset.names = friend, weight = c(0.259,.534,.207)), -->
<!--                wealth.index = T) -->
<!-- ``` -->

<!-- - **Hint:** Read about `PerformanceAnalytics::Return.portfolio()` -->

# Settling In {data-background=#e8d725}

## Remember the Goal

"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'" -Isaac Asimov

> - [Remembering Good Principles](https://youtu.be/fSgEeI2Xpdc)
> - [Rauser view on time and data](https://www.youtube.com/embed/coNDCIMH8bk?start=628) - 10:28 to 17:50

## Edward Tufte

> Graphical excellence is that which gives to the viewer the greatest number of ideas in the shortest time with the least ink in the smallest space

> Edward Tufte

# Next Class {data-background=#e8d725}

## dygraphs: R connection to dygraphs JavaScript charting library

Open the [dygraphs help website](http://rstudio.github.io/dygraphs/index.html) and implement one of their examples in your local R session.
