 # 10 quick plots in R with ggplot2

With the  ggplot2 package in R it is possible to create almost any type of chart. Sometimes it takes me more time than I want to just create a simple plot, because I forgot what the data structure should look like or the syntax of the formulas. Therefore, I’ve listed 10 plots below with codes to make it as easy as possible to use whenever I need them.

1. Barchart
2. Histogram
3. Line chart
4. Line chart with confidence interval
5. Coordinate plot
6. Donut chart
7. Scatter plot
8. Scatter plot with shapes
9. Boxplot
10. Correlation plot

## Data preparation

So let’s start with the prep stuff. First install and unpack the  ggplot2 package. Second create a simple dataframe with some dimensions and measures. I’ve kept it as simple as possible, so this is what the dataframe looks like:

This is all the data we need for the next 10 charts.

## 1. Bar chart

So the very simplest chart is (no surprise) the bar chart. ## 2. Histogram

Next chart is the histogram. I added a grey border around the bins, by default it won’t show space between the bars. ## 3. Line chart

Just like the bar chart, the line chart doesn’t need any arguments in the function. ## 4. Line chart with confidence interval

Next up is the line chart from above, but then we add a confidence interval. ## 5. Coordinate plot

A colorful coordinate plot showing the frequency of the dimensions. ## 6. Donut chart

The exact same information as the coordinate plot, but then presented differently. Simply change the theta into  y. ## 7. Scatter plot

A scatter plot with simple dots. ## 8. Scatter plot with shapes

The same scatter plot as previous plot, but then with shapes. ## 9. Boxplot

Multiple boxplots in one chart with the following code: ## 10. Correlation plot

And last but not least, the correlation plot. This is just a simple one, read my other post on how to plot a correlation matrix in 4 different ways. So these are the 10 easy plots created with ggplot2 . If you want to know more variations, then check out this amazing cheatsheet from Rstudio. ### Who I am

Hi! My name is Claudia, a freelance data analyst/scientist. This is my space on the internet where I share knowledge and experience with everyone who wants to become a better analyst. Read more about my work as a freelancer here.