# install.packages("esquisse") library(esquisse)
# install.packages("esquisse") library(esquisse)
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!
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
Using the esquisser()
function you can start creating a plot for a data.frame
or tibble
. That’s it!
esquisser(er)
esquisse::esquisser(er, viewer = "browser")
To select variables you can drag and drop variables to the respective axis that you would like the variable to be plotted on.
To select variables you can drag and drop variables to the respective axis that you would like the variable to be plotted on.
esquisse
automatically assumes a plot type, but you might want to change this.
Facets create multiple plots based on the different values of a variable.
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.
For plots with points use the color region to change coloring according to a variable. (use “fill” for bar plots)
You can change the overall appearance with “Geometries” and “Theme”.
To change titles on your plot, use the “Labels & Titles” tab.
You can also easily view data
You’ll need to “interrupt” Esquisse to launch it with a new dataset.
If you don’t see the stop button, you need to resize your window.
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…
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)
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>, …
esquisser(wide_er) # only one county at a time? Tricky! esquisser(long_er) # county as color, visits as y, year as x!
Why use Esquisse?
A. Explore your data
B. Get a “head start” on your code
C. Both of these!
esquisse
ggquickeda
: https://smouksassi.github.io/ggquickeda/ggraptR
: https://github.com/cargomoose/ggraptR/autoplot
can be helpful for some packages (see this blog post)esquisser()
function on a datasetviewer = "browser"
argument to launch in your browser.💻 Lab
Image by Gerd Altmann from Pixabay