Creating basic plots with ggplot2
In this recipe, we demonstrate how to use The Grammar of Graphics to construct our very first ggplot2
chart with the superstore sales dataset.
Getting ready
First, download the superstore_sales.csv
dataset from the https://github.com/ywchiu/rcookbook/raw/master/chapter7/superstore_sales.csv GitHub link.
Next, you can use the following code to download the CSV file to your working directory:
> download.file('https://github.com/ywchiu/rcookbook/raw/master/chapter7/superstore_sales.csv', 'superstore_sales.csv')
You will also need to load the dplyr
package to manipulate the superstore_sales
dataset.
How to do it…
Please perform the following steps to create a basic chart with ggplot2
:
- First, install and load the
ggplot2 ...
Get R for Data Science Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.