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

## Esquisse Package

```{r esquisse}
# install.packages("esquisse")
library(esquisse)
```

## Esquisse Package

The [`esquisse` package](https://cran.r-project.org/web/packages/esquisse/vignettes/get-started.html) is helpful for getting used to creating plots in R.

It is an interactive tool to help you in RStudio.

It's super **nifty**!
```{r, fig.alt="starting a plot", out.width = "50%", echo = FALSE, fig.align='center'}
knitr::include_graphics("https://c.tenor.com/DNUSO9MjrTEAAAAC/bob-ross.gif")
```

## Starting a plot

Using the `esquisser()` function you can start creating a plot for a `data.frame` or `tibble`. That's it!

```{r, eval = FALSE}
esquisser(mtcars)
```

```{r, fig.alt="starting a plot", out.width = "90%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/start_a_plot.png")
```

## Show the plot in the browser

```{r, eval = FALSE}
esquisse::esquisser(iris, viewer = "browser")
```

## Select Variables

To select variables you can drag and drop variables to the respective axis that you would like the variable to be plotted on.

```{r, fig.alt="select variables", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/variables.gif")
```

## Find code

To select variables you can drag and drop variables to the respective axis that you would like the variable to be plotted on.

```{r, fig.alt="select variables", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/get_code.gif")
```

## Change plot type

`esquisse` automatically assumes a plot type, but you might want to change this.

```{r, fig.alt="change plot type", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/change_type_short.gif")
```

## Add Facets

Facets create multiple plots based on the different values of a variable.

```{r, fig.alt="add facets", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/facet.gif")
```

## Add size

Sometimes it is useful to change the way points are plotted so that size represents a variable. This can especially be helpful if you need your plot to be black and white.

```{r, fig.alt="add color", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/size.gif")
```

## Add color

For plots with points use the color region to change coloring according to a variable.
(use "fill" for bar plots)

```{r, fig.alt="add color", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/color.gif")
```

## Appearance

You can change the overall appearance with the appearance tab.

```{r, fig.alt="change overall appearance", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/appearance.gif")
```

## Smooth Lines

Especially when you have a scatter plot, it can be helpful to add a smooth/trend line. 

```{r, fig.alt="add smooth line", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/smooth.gif")
```

## Change titles

To change titles on your plot, use the titles tab.

```{r, fig.alt="change titles", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/titles.gif")
```

## View data

You can also easily view data

```{r, fig.alt="Click on the table button to view a table of your data.", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/view_data.png")
```

## Interrupting Esquisse

You'll need to "interrupt" Esquisse to launch it with a new dataset.

Use the stop button or press ctrl+c to stop the Esquisse app.

```{r, fig.alt="Click the stop button to interrupt the Esquisse app.", out.width = "100%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/stop.png")
```

## Wide & Long Data Example

```{r}
wide_circ <- read_csv("https://hutchdatascience.org/SeattleStatSummer_R/data/Charm_City_Circulator_Ridership.csv")
```

## Wide Data

```{r}
library(dplyr)
glimpse(wide_circ)
```


## Long Data

```{r}
library(tidyr)
long_circ <- wide_circ %>%
  pivot_longer(
    cols = contains(c("boarding")),
    names_to = "Route",
    values_to = "Boardings"
  )
```

## Long Data

```{r}
glimpse(long_circ)
```

## Make a plot of boardings by day for different routes

```{r, eval = FALSE}
esquisser(wide_circ) # days as x...? Tricky!
esquisser(long_circ) # day as x, Boardings as y, Route as fill
```

## Summary

* Use the `esquisser()` function on a dataset
* Use the `viewer = "browser"` argument to launch in your browser.
* Code from Esquisse can copied into code chunks to be generated in the "Plots" pane
* It's easier if your code is in "long" form!


🏠 [Workshop Website](https://hutchdatascience.org/SeattleStatSummer_R/)

