Plotting Data Using ggplot2 in R

Create elegant data visualizations using the Grammar of Graphics

Namitha Deshpande
The Startup

--

Photo by Andrey Haimin on Unsplash

Being able to create visualizations or graphical representations of data at hand is a key step in being able to communicate information and findings to others from a non-technical background.

In this story, you will learn to use the ggplot2 library in R to declaratively make beautiful plots or charts of your data.

What is Data Visualization?

Wiki says “Data visualization is the graphic representation of data. It involves producing images that communicate relationships among the represented data to viewers of the images.”

What is ggplot2?

ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics. You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.- Tidyverse.org

The inputs we are interested in are:

  1. Call the ggplot(df) function which creates a blank canvas with the dataset(df) of interest
  2. Specify aesthetic mappings, which specifies how you want to map variables to visual aspects. In this case, we are simply mapping the variables to the…

--

--