Introduction

Could you imagine if there was a feature on RStudio that enables users to create basic plots using drag and drop feature? Good news! It does exist! By using the esquisse library, you can create your own plots without coding! It is great for beginners in R. And how does it work? Let’s see it now!

Using esquisse library

I already have my data! I just want to create a plot!

Alright! Install and load the esquisse package and jump to using esquisse.

I don’t have any data! I will follow step by step from CSV import to creating plots using esquisse!

To follow all my steps make sure to download the CSV file located here.

This file contains daily information about maximum temperature observed in a Sydney station since 1889! I would like to see whether the temperature has been raising since then.

First, make sure you install tidyverse and esquisse running the following code on your console:

install.packages(c("tidyverse", "esquisse"))

After that, we should invoke these libraries:

library(tidyverse)
## -- Attaching packages ------------------------------------------------ tidyverse 1.2.1 --
## v ggplot2 3.2.0     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   0.8.3     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts --------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(esquisse)

Now, we need to create an object and read the CSV file with the data we want to plot. In this case, it is the CSV that we have just downloaded.

temperatureTable <- read.csv("max_temp_australia_66062.csv")

Great! Let’s see what this CSV contains.

glimpse(temperatureTable)
## Observations: 47,705
## Variables: 5
## $ station         <int> 66062, 66062, 66062, 66062, 66062, 66062, 6606...
## $ YYYY.MM.DD      <fct> 1889-01-01, 1889-01-02, 1889-01-03, 1889-01-04...
## $ max_temp        <dbl> 26.1, 25.6, 26.9, 21.6, 23.9, 25.7, 21.2, 22.3...
## $ max_temp_source <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
## $ metadata        <fct> "name=SYDNEY (OBSERVATORY HILL)               ...

Well, it seems that the YYYY.MM.DD attribute needs to be converted to Date format!

temperatureTable$YYYY.MM.DD <- as.Date(temperatureTable$YYYY.MM.DD)
##  Date[1:47705], format: "1889-01-01" "1889-01-02" "1889-01-03" "1889-01-04" "1889-01-05" ...

As I want to group temperature values by year, it is necessary to separate the year from the date.

temperatureTable <- temperatureTable %>% separate(YYYY.MM.DD,c("Year", "Month", "Day"), remove = FALSE)
## Observations: 47,705
## Variables: 8
## $ station         <int> 66062, 66062, 66062, 66062, 66062, 66062, 6606...
## $ YYYY.MM.DD      <date> 1889-01-01, 1889-01-02, 1889-01-03, 1889-01-0...
## $ Year            <chr> "1889", "1889", "1889", "1889", "1889", "1889"...
## $ Month           <chr> "01", "01", "01", "01", "01", "01", "01", "01"...
## $ Day             <chr> "01", "02", "03", "04", "05", "06", "07", "08"...
## $ max_temp        <dbl> 26.1, 25.6, 26.9, 21.6, 23.9, 25.7, 21.2, 22.3...
## $ max_temp_source <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
## $ metadata        <fct> "name=SYDNEY (OBSERVATORY HILL)               ...

Now, I’m converting the Year attribute from string to integer

temperatureTable$Year <- strtoi(temperatureTable$Year)
##  int [1:47705] 1889 1889 1889 1889 1889 1889 1889 1889 1889 1889 ...

Great! Now, let’s calculate the mean maximum temperature of each year and update the temperatureTable object!

temperatureTable <- temperatureTable %>% group_by(Year) %>% summarise(maxTemp = max(max_temp,na.rm = TRUE),meanMaxTemperature = mean(max_temp,na.rm = TRUE))
## Observations: 131
## Variables: 3
## $ Year               <int> 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1...
## $ maxTemp            <dbl> 39.3, 34.5, 36.4, 32.2, 34.2, 36.4, 35.6, 4...
## $ meanMaxTemperature <dbl> 20.76986, 20.52110, 20.65260, 20.34563, 20....

Now that we have prepared our data, let’s visualise it! Time to use the esquisse library! Use this command on your console!

esquisse::esquisser()

Alternatively, you can also use the Addins menu

Using esquisse

Using esquisse

As you can see, a new window is opened. You must choose your data.frame and select all the variables that will be used in your plot!

Choose a data.frame

Choose a data.frame

In this window, you can drag and drop the variables in your plot, change your plot type, filter values, add titles, etc!

Customise your plot

Customise your plot

After your plot is complete, click on Export & code! It is possible to copy the ggplot code to your script, as well as export the plot in image or pptx format!

Export & Code

Export & Code

My code generated by esquisse was the following:

ggplot(temperatureTable) +
    aes(x = Year, y = meanMaxTemperature, colour = meanMaxTemperature) +
    geom_line(size = 1L) +
    scale_color_distiller(palette = "RdYlBu") +
    labs(x = "Year", y = "Mean maximum temperature", title = "Mean maximum temperature over Years", color = " ") +
    theme_classic()

Now lets add a regression line to see how the temperature has been raising! Add this command to your ggplot function!

    geom_smooth(method='lm', color = "black", size = 0.5)

In order to show more values in your x axis, you can also add the following command to your ggplot function:

    scale_x_continuous(breaks = temperatureTable$Year[seq(1, length(temperatureTable$Year), by = 10)])

Your final ggplot function should look like this!

ggplot(temperatureTable) +
    aes(x = Year, y = meanMaxTemperature, colour = meanMaxTemperature) +
    geom_line(size = 1L) +
    scale_color_distiller(palette = "RdYlBu") +
    labs(x = "Year", y = "Mean maximum temperature", title = "Mean maximum temperature over Years", color = " ") +
    theme_classic()+
    geom_smooth(method='lm', color = "black", size = 0.5) +
    scale_x_continuous(breaks = temperatureTable$Year[seq(1, length(temperatureTable$Year), by = 10)])

Well, the maximum temperature does seem to be raising over the years! That is something that we should worry about!

Limitations

Esquisse package cannot provide all ggplot functionalities, such as adding regression line, changing axis scales, coloring based on axis values, etc. It is intended to be be used by beginners or for creating basic plots.

Conclusion

Although esquisse creates simple plots, it definitely helps beginners in R to create plots without coding or to understand its usage. Advanced users may prefer coding as it provides more functionalities.

References

https://CRAN.R-project.org/package=esquisse

https://cran.r-project.org/web/packages/esquisse/vignettes/get-started.html