# Graphics in R (Gallery with Examples)

This page shows an overview of (almost all) different types of graphics, plots, charts, diagrams, and figures of the R programming language.

Each type of graphic is illustrated with some **basic example code**. These codes are based on the following data:

set.seed(123) # Set seed for reproducibility x <- rnorm(30) # Create x variable y <- x + rnorm(30) # Create correlated y variable |

set.seed(123) # Set seed for reproducibility x <- rnorm(30) # Create x variable y <- x + rnorm(30) # Create correlated y variable

In each section, you can find additional resources on how to create and modify these graphic types yourself (including reproducible R syntax and many examples).

Here is a **list of all graphics** of this article:

So without further ado, let’s dive in!

## Barplot

**Barplot Definition:** A barplot (or barchart) illustrates the association between a numeric and a categorical variable. The barplot represents each category as a bar and reflects the corresponding numeric value with the bar’s size.

The following R syntax shows how to draw a basic barplot in R:

barplot(x) # Draw barplot in R |

barplot(x) # Draw barplot in R

Our example barplot looks a follows:

**Advanced Barplots:** There are no advanced barplots yet.

**Barplot Resources:** There a no further resources yet.

## Boxplot

**Boxplot Definition:** A boxplot (or box-and-whisker plot) displays the distribution of a numerical variable based on five summary statistics: minimum non-outlier; first quartile; median; third quartile; and maximum non-outlier. Furthermore, boxplots show the positioning of outliers and whether the data is skewed.

The following R syntax shows how to draw a basic boxplot in R:

boxplot(x) # Draw boxplot in R |

boxplot(x) # Draw boxplot in R

**Advanced Boxplots:** Find some advanced boxplots below. Click on the images to get more information and example R codes for each of the boxplots.

**Boxplot Resources:** Find some further resources on the creation of boxplots below.

## Density Plot

**Density Plot Definition:** A density plot (or kernel density plot; density trace graph) shows the distribution of a numerical variable over a continuous interval. Peaks of a density plot visualize where the values of numerical variables are concentrated.

The following R syntax shows how to draw a basic density plot in R:

plot(density(x)) # Draw density plot in R |

plot(density(x)) # Draw density plot in R

**Advanced Density Plots:** There are no advanced density plots yet.

**Density Plot Resources:** There a no further resources yet.

## Heatmap

**Heatmap Definition:** A heatmap (or shading matrix) visualizes individual values of a matrix with colors. More common values are typically indicated by brighter reddish colors and less common values are typically indicated by darker colors.

The following R syntax shows how to draw a basic heatmap in R:

heatmap(cbind(x, y)) # Draw heatmap in R |

heatmap(cbind(x, y)) # Draw heatmap in R

**Advanced Heatmaps:** There are no advanced heatmaps yet.

**Heatmap Resources:** There a no further resources yet.

## Histogram

**Histogram Definition:** A histogram groups continuous data into ranges and plots this data as bars. The height of each bar shows the amount of observations within each range.

The following R syntax shows how to draw a basic histogram in R:

hist(x) # Draw histogram in R |

hist(x) # Draw histogram in R

**Advanced Histograms:** There are no advanced histograms yet.

**Histogram Resources:** There a no further resources yet.

## QQplot

**QQplot Definition:** A QQplot (or Quantile-Quantile plot; Quantile-Quantile diagram) determines whether two data sources come from a common distribution. QQplots draw the quantiles of the two numerical data sources against each other. If both data sources come from the same distribution, the points fall on a 45 degree angle.

The following R syntax shows how to draw a basic QQplot in R:

qqplot(x, y) # Draw QQplot in R |

qqplot(x, y) # Draw QQplot in R

**Advanced QQplots:** There are no advanced QQplots yet.

**QQplot Resources:** There a no further resources yet.

## Scatterplot

**Scatterplot Definition:** A scatterplot (or scatter plot; scatter graph; scatter chart; scattergram; scatter diagram) displays two numerical variables with points, whereby each point represents the value of one variable on the x-axis and the value of the other variable on the y-axis.

The following R syntax shows how to draw a basic scatterplot in R:

plot(x, y) # Draw scatterplot in R |

plot(x, y) # Draw scatterplot in R

**Advanced Scatterplots:** Find some advanced scatterplots below. Click on the images to get more information and example R codes for each of the scatterplots.

**Scatterplot Resources:** Find some further resources on the creation of scatterplots below.

## Venn Diagram

**Venn Diagram Definition:** A venn diagram (or primary diagram; set diagram; logic diagram) illustrates all possible logical relations between certain data characteristics. Each characteristic is represented as a circle, whereby overlapping parts of the circles illustrate elements that have both characteristics at the same time.

The following R syntax shows how to draw a basic venn diagram in R:

install.packages("VennDiagram") # Install VennDiagram package library("VennDiagram") # Load VennDiagram package plot.new() # Draw empty plot draw.single.venn(area = 10) # Draw venn diagram |

install.packages("VennDiagram") # Install VennDiagram package library("VennDiagram") # Load VennDiagram package plot.new() # Draw empty plot draw.single.venn(area = 10) # Draw venn diagram

**Advanced Venn Diagrams:** There are no advanced venn diagrams yet.

**Venn Diagram Resources:** There a no further resources yet.

## General Modification of Plots

In the previous part of this article, I have shown you many different **types of plots**. However, there are plenty of programming tricks for the modification of plots in general. In the following, you will find a list of tutorials that explain such general modifications of plots in R.

### Base R Plots

### ggplot2

## Learn More About Plots in R

This tutorial showed an overview of many different graphics and plots of the R programming language. If you want to learn more details about the creation of plots in R, I can recommend the following YouTube video of the DataCamp YouTube channel:

If you want to learn more about the R programming language in general, you could have a look at the following two links. They show a list of useful R functions…

… and give an overview of all R programming tutorials on this website:

I hope you liked this gallery of R graphics! If you have further questions or any kind of feedback, don’t hesitate to let me know in the comments below.

Also, don’t forget to subscribe to my free statistics newsletter for regular updates on programming and statistics!

### Subscribe to my free statistics newsletter:

### R Tutorials

abs Function in R

all & any R Functions

Set Aspect Ratio of Plot

attach & detach R Functions

attr, attributes & structure in R

cbind R Command

Change ggplot2 Legend Title

Character to Numeric in R

Check if Object is Defined

col & row sums, means & medians

Complete Cases in R

Concatenate Vector of Strings

Convert Date to Weekday

cumsum R Function

Data Frame Column to Numeric

diff Command in R

difftime R Function

dim Function in R

dir R Function

Disable Scientific Notation

Draw Segments in R

droplevels R Example

Evaluate an Expression

Extract Characters from String

Factor to Numeric in R

Format Decimal Places

get, get0 & mget in R

is.na R Function

is.null Function in R

jitter R Function

Join Data with dplyr Package

length Function in R

lowess R Smoothing Function

max and min Functions in R

NA Omit in R

nchar R Function

ncol Function in R

nrow Function in R

outer Function in R

pairs & ggpairs Plot

parse, deparse & R expression

paste & paste0 Functions in R

pmax and pmin R Functions

polygon Plots in R

pretty R Function

R Find Missing Values

R Functions List (+ Examples)

R NA – Values

R Replace NA with 0

rbind & rbind.fill in R

Read Excel Files in R

readLines, n.readLines & readline

Remove Element from List

Remove Legend in ggplot2

Rename Column Name in R

Replace Last Comma of String

rev R Command

Round Numeric Data in R

Save & Load RData Workspace

scan R Function

setdiff R Function

setNames vs. setnames in R

sink Command in R

Sort, Order & Rank Data in R

sprintf Function in R

Square Root in R

str_c Function of stringr Package

str_sub Function of stringr Package

strptime & strftime Functions

substr & substring R Commands

sweep R Function

Transform Data Frames

union Function in R

unlist in R

weekdays, months, quarters & julian in R

with & within R Functions

Write Excel File in R