grafify: Make great-looking ggplot2 graphs quickly with R

Written by Matt Dancho on June 15, 2021



This article is part of R-Tips Weekly, a weekly video tutorial that shows you step-by-step how to do common R coding tasks.


Here are the links to get set up. 👇

grafify Video Tutorial
For those that prefer Full YouTube Video Tutorials.

Learn how to use grafify in our free 7-minute YouTube video.

(Click image to play tutorial)

Watch our full YouTube Tutorial

What is grafify?

grafify is a new R package for making great-looking ggplot2 graphs quickly in R. It has 19 plotting functions that simplify common ggplot graphs and provide color-blind friendly themes.

Image Credit: grafify package

We’ll go through a short tutorial to get you up and running with grafify.

Before we get started, get the R Cheat Sheet

grafify is great for making quick ggplot2 plots. But, you’ll still need to learn how to wrangle data with dplyr and visualize data with ggplot2. For those topics, I’ll use the Ultimate R Cheat Sheet to refer to dplyr and ggplot2 code in my workflow.

Quick Example:

Download the Ultimate R Cheat Sheet. Then Click the “CS” next to “ggplot2” opens the Data Visualization with ggplot2 Cheat Sheet.

Now you’re ready to quickly reference ggplot2 functions.

ggplot2 cheat sheet

Onto the tutorial.

How grafify works

The grafify package extends ggplot2 by adding several simplified plotting functions. In this tutorial, we’ll cover:

  • 2-Variable Functions: plot_scatterbar_sd(), plot_scatterbox(), and plot_dotviolin()

  • 3-Variable Functions: plot_3d_scatterbox()

  • Before-After Functions: plot_befafter_colors()

Load the Libraries and Data

First, run this code to:

  1. Load Libraries: Load grafify and tidyverse.
  2. Import Data: We’re using the mpg dataset that comes with ggplot2.

Get the code.

Scatterbar SD Plot

First, we can make a Scatterbar Plot that shows the data points along with error bars at a standard deviation. Simply use plot_scatterbar_sd().

Get the code.

Scatterbox Plot

Next, we can make a Scatterbox Plot that shows a custom boxplot / jitter plot combination. I’ve added a jitter point to show the distribution. Simply use plot_scatterbox().

Get the code.

Dotviolin Plot

Next, we can make a Dotviolin Plot that shows a custom violin plot / dotplot combination. Simply use plot_dotviolin().

Get the code.

Scatterbox 3D Plot

Next, we can make a 3D Scatterbox Plot that shows three variables using boxplot / jitter plot combination. This is great for drilling into multiple categories. Simply use plot_3d_scatterbox().

Get the code.

Before-After Plot

Finally, we can make a Before-After Plot that shows changes between two states (in this case how various models changed in MPG Fuel Efficiency from 1999 to 2008). This is great for comparing two states. Simply use plot_befafter_colors().

Get the code.

Summary

With 19 plotting functions, the grafify package makes it quick and easy to make custom ggplot2 visualizations that are easy to visualize and explore data. With that said, it’s critical to learn ggplot2 for plots beyond what grafify offers.

If you’d like to learn ggplot2 and data science for business, then read on. 👇

My Struggles with Learning Data Science

It took me a long time to learn data science. And I made a lot of mistakes as I fumbled through learning R. I specifically had a tough time navigating the ever increasing landscape of tools and packages, trying to pick between R and Python, and getting lost along the way.

If you feel like this, you’re not alone.

In fact, that’s the driving reason that I created Business Science and Business Science University (You can read about my personal journey here).

What I found out is that:

  1. Data Science does not have to be difficult, it just has to be taught smartly

  2. Anyone can learn data science fast provided they are motivated.

How I can help

If you are interested in learning R and the ecosystem of tools at a deeper level, then I have a streamlined program that will get you past your struggles and improve your career in the process.

It’s called the 5-Course R-Track System. It’s an integrated system containing 5 courses that work together on a learning path. Through 5+ projects, you learn everything you need to help your organization: from data science foundations, to advanced machine learning, to web applications and deployment.

The result is that you break through previous struggles, learning from my experience & our community of 2000+ data scientists that are ready to help you succeed.

Ready to take the next step? Then let’s get started.




👇 Top R-Tips Tutorials you might like:

  1. mmtable2: ggplot2 for tables
  2. ggside: Plot linear regression with marginal distributions
  3. DataEditR: Interactive Data Editing in R
  4. openxlsx: How to Automate Excel in R
  5. officer: How to Automate PowerPoint in R
  6. DataExplorer: Fast EDA in R
  7. esquisse: Interactive ggplot2 builder
  8. gghalves: Half-plots with ggplot2
  9. rmarkdown: How to Automate PDF Reporting
  10. patchwork: How to combine multiple ggplots

Want these tips every week? Join R-Tips Weekly.