---
title: "Getting Started with healthyR"
subtitle: "A Quick Introduction"
author: "Steven P. Sanderson II, MPH"
date: "`r Sys.Date()`"
output: 
  rmarkdown::html_vignette:
    toc: true
    toc_depth: 2
vignette: >
  %\VignetteIndexEntry{Getting Started with healthyR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, echo = FALSE, message = FALSE, warning = FALSE}
knitr::opts_chunk$set(
    message = FALSE,
    warning = FALSE,
    fig.width = 8, 
    fig.height = 4.5,
    fig.align = 'center',
    out.width='95%', 
    dpi = 100,
    collapse = TRUE,
    comment = "#>"
)
```

> healthyR: A toolkit for hospital data

# Libaray Load

First things first, lets load in the library:
```{r setup}
library(healthyR)
```

# Generate Sample Data

First we are going to take a look at some time series plotting functions. These
are fairly straight forward and therefore should seem intuitive. We are going
to generate some random numbers to simulate different daily average length of 
stay data. We will set a seed for reproducibility.

```{r random_los_data}
set.seed(123)

# Library Load ----
suppressPackageStartupMessages(library(healthyR))
suppressPackageStartupMessages(library(timetk))
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(purrr))

# Make A Series of Dates ----
ts_tbl <- tk_make_timeseries(
  start = "2019-01-01"
  , by = "day"
  , length_out = "1 year 6 months"
)

# Set Values ----
values <- runif(548, 5, 10)

# Make tibble ----
df_tbl <- tibble(x = ts_tbl, y = values) %>% set_names("Date","Values")
```

# Plot the Time Series

Now that we have our data lets see how easy it is to generate an ALOS chart:

```{r alos_plot}
ts_alos_plt(
  .data = df_tbl
  , .date_col = Date
  , .value_col = Values
  , .by = "month"
  , .interactive = FALSE
)
```

And with the `.interactive` option set to __TRUE__:

```{r alos_plot_interactive}
ts_alos_plt(
  .data = df_tbl
  , .date_col = Date
  , .value_col = Values
  , .by = "month"
  , .interactive = TRUE
)
```

As we can see, this function has the ability to return either a static plot or
and interactive plot. Under the hood it is using the `timetk::plot_time_series`
function. You can find out more on the the timetk function [here.](https://business-science.github.io/timetk/reference/plot_time_series.html)

That is the end of this first and very quick tutorial on the `ts_alos_plt` function.
