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

Starting a plot

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

esquisser(mtcars)

starting a plot

Show the plot in the browser

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.

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 the appearance tab.

change overall appearance

Smooth Lines

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

add smooth line

Change titles

To change titles on your plot, use the 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.

Use the stop button or press ctrl+c 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 Example

library(jhur)
library(dplyr)
wide_circ <- read_circulator()
glimpse(wide_circ)
## Rows: 1,146
## Columns: 15
## $ day              <chr> "Monday", "Tuesday", "Wednesday", "Thursday", "Friday…
## $ date             <chr> "01/11/2010", "01/12/2010", "01/13/2010", "01/14/2010…
## $ orangeBoardings  <dbl> 877, 777, 1203, 1194, 1645, 1457, 839, 999, 1023, 137…
## $ orangeAlightings <dbl> 1027, 815, 1220, 1233, 1643, 1524, 938, 1000, 1047, 1…
## $ orangeAverage    <dbl> 952.0, 796.0, 1211.5, 1213.5, 1644.0, 1490.5, 888.5, …
## $ purpleBoardings  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ purpleAlightings <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ purpleAverage    <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ greenBoardings   <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ greenAlightings  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ greenAverage     <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ bannerBoardings  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ bannerAlightings <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ bannerAverage    <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ daily            <dbl> 952.0, 796.0, 1211.5, 1213.5, 1644.0, 1490.5, 888.5, …

Long Data

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

Long Data

glimpse(long_circ)
## Rows: 4,584
## Columns: 13
## $ day              <chr> "Monday", "Monday", "Monday", "Monday", "Tuesday", "T…
## $ date             <chr> "01/11/2010", "01/11/2010", "01/11/2010", "01/11/2010…
## $ orangeAlightings <dbl> 1027, 1027, 1027, 1027, 815, 815, 815, 815, 1220, 122…
## $ orangeAverage    <dbl> 952.0, 952.0, 952.0, 952.0, 796.0, 796.0, 796.0, 796.…
## $ purpleAlightings <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ purpleAverage    <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ greenAlightings  <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ greenAverage     <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ bannerAlightings <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ bannerAverage    <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ daily            <dbl> 952.0, 952.0, 952.0, 952.0, 796.0, 796.0, 796.0, 796.…
## $ Route            <chr> "orangeBoardings", "purpleBoardings", "greenBoardings…
## $ Boardings        <dbl> 877, NA, NA, NA, 777, NA, NA, NA, 1203, NA, NA, NA, 1…

Make a plot of boardings by day for different routes

esquisser(wide_circ) # days as x...? Tricky!
esquisser(long_circ) # day as x, Boardings as y, Route as fill

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