Esquisse Package

# install.packages("esquisse")
library(esquisse)

Esquisse Package

The esquisse package is helpful for getting used to creating plots in R.

It is an interactive tool to help you in RStudio.

It’s super nifty! starting a plot

First, get some data..

We can use the CO heat-related ER visits dataset. This dataset contains information about the number and rate of visits for heat-related illness to ERs in Colorado from 2011-2022, adjusted for age.

er <-
  read_csv("https://daseh.org/data/CO_ER_heat_visits.csv")

head(er)
## # A tibble: 6 × 6
##   county  rate lower95cl upper95cl visits  year
##   <chr>  <dbl>     <dbl>     <dbl>  <dbl> <dbl>
## 1 Adams   6.73     NA         9.24     29  2011
## 2 Adams   4.84      2.85     NA        23  2012
## 3 Adams   6.84      4.36      9.31     31  2013
## 4 Adams   3.08      1.71      4.85     15  2014
## 5 Adams   3.36      1.89      5.23     16  2015
## 6 Adams   8.85      6.12     11.6      42  2016

Starting a plot

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

esquisser(er)

starting a plot

Show the plot in the browser

esquisse::esquisser(er, 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.

select variables

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.

select variables

Change plot type

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

change plot type

Add Facets

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

add facets

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.

add color

Add color

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

add color

Appearance

You can change the overall appearance with “Geometries” and “Theme”.

change overall appearance

Change titles

To change titles on your plot, use the “Labels & Titles” tab.

change titles

View data

You can also easily view data

Click on the table button to view a table of your data.

Interrupting Esquisse

You’ll need to “interrupt” Esquisse to launch it with a new dataset.

  1. Close the tab/window
  2. Use the stop button to stop the Esquisse app

If you don’t see the stop button, you need to resize your window.

Click the stop button to interrupt the Esquisse app.

Wide & Long Data ?

Let’s look at why we might want long data using Esquisse.

library(tidyverse)
long_er <- er |> 
  select(c("county", "year", "visits"))
glimpse(long_er)
## Rows: 768
## Columns: 3
## $ county <chr> "Adams", "Adams", "Adams", "Adams", "Adams", "Adams", "Adams", …
## $ year   <dbl> 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 202…
## $ visits <dbl> 29, 23, 31, 15, 16, 42, 32, 37, 36, 24, 35, 45, 0, 0, NA, 0, NA…

Wide Data

As a comparison, let’s also load a wide version of this dataset.

wide_er <- er |> 
  select(county, visits, year) |>
  pivot_wider(names_from = county, values_from = visits)

Wide vs Long Data

head(long_er)
## # A tibble: 6 × 3
##   county  year visits
##   <chr>  <dbl>  <dbl>
## 1 Adams   2011     29
## 2 Adams   2012     23
## 3 Adams   2013     31
## 4 Adams   2014     15
## 5 Adams   2015     16
## 6 Adams   2016     42
head(wide_er)
## # A tibble: 6 × 65
##    year Adams Alamosa Arapahoe Archuleta  Baca  Bent Boulder Broomfield Chaffee
##   <dbl> <dbl>   <dbl>    <dbl>     <dbl> <dbl> <dbl>   <dbl>      <dbl>   <dbl>
## 1  2011    29       0       33         0     0     0      12         NA       0
## 2  2012    23       0       27         0     0    NA      13         NA      NA
## 3  2013    31      NA       20         0     0     0      12         NA      NA
## 4  2014    15       0       NA         0     0    NA      19         NA      NA
## 5  2015    16      NA       31         0     0    NA      14         NA      NA
## 6  2016    42      NA       39         0     0    NA      18         NA       0
## # ℹ 55 more variables: Cheyenne <dbl>, `Clear Creek` <dbl>, Conejos <dbl>,
## #   Costilla <dbl>, Crowley <dbl>, Custer <dbl>, Delta <dbl>, Denver <dbl>,
## #   Dolores <dbl>, Douglas <dbl>, Eagle <dbl>, Elbert <dbl>, `El Paso` <dbl>,
## #   Fremont <dbl>, Garfield <dbl>, Gilpin <dbl>, Grand <dbl>, Gunnison <dbl>,
## #   Hinsdale <dbl>, Huerfano <dbl>, Jackson <dbl>, Jefferson <dbl>,
## #   Kiowa <dbl>, `Kit Carson` <dbl>, Lake <dbl>, `La Plata` <dbl>,
## #   Larimer <dbl>, `Las Animas` <dbl>, Lincoln <dbl>, Logan <dbl>, …

Make a plot of visits by year for different counties

esquisser(wide_er) # only one county at a time? Tricky!
esquisser(long_er) # county as color, visits as y, year as x!

GUT CHECK!

Why use Esquisse?

A. Explore your data

B. Get a “head start” on your code

C. Both of these!

Some Alternatives to esquisse

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!

Lab