All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (2024)

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

Here is a list of all graph types that are illustrated in this article:

  • Barplot
  • Boxplot
  • Density Plot
  • Heatmap
  • Histogram
  • Line Plot
  • Pairs Plot
  • Polygon Plot
  • QQplot
  • Scatterplot
  • Venn Diagram

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 reproducibilityx <- rnorm(30) # Create x variabley <- 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).

In addition, this article contains a list of tutorials for general plot modifications in:

  • Base R
  • ggplot2

So without further ado, let’s dive in!

Barplot

Barplot Definition: A barplot (or barchart; bargraph) 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

Our example barplot looks a follows:

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (1)

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

Barplot Resources: Find some further resources on the creation of barplots below.

  • How to Create a Barplot in R
  • Order Bars of ggplot2 Barchart in R

Barplot Video Tutorial: The following video shows a tutorial on creating barplots in R.

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (8)

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.

  • How to Create a Boxplot in R
  • Overlay Boxplot with Jittered Variable

Boxplot Video Tutorial: The following video shows a tutorial on creating boxplots in R.

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (14)

Advanced Density Plots: Find some advanced density plots below. Click on the images to get more information and example R codes for each of the density plots.

Density Plot Resources: Find some further resources on the creation of density plots below.

  • Kernel Density Plot in Base R (density Function)
  • The plot() Function in R
  • Draw Multiple Normally Distributed Density Plots in R

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (17)

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

Heatmap Resources: Find some further resources on the creation of heatmaps below.

  • Create Heatmap in R (Base R vs. ggplot2 vs. plotly)

Heatmap Video Tutorial: The following video shows a tutorial on creating heatmaps in R.

Line Plot

Line Plot Definition: A line plot (or line graph; line chart) visualizes values along a sequence (e.g. over time). Line plots consist of an x-axis and a y-axis. The x-axis usually displays the sequence and the y-axis the values corresponding to each point of the sequence.

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

plot(1:length(y), y, type = "l") # Draw line plot in R

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (21)

Advanced Line Plots: Find some advanced line plots below. Click on the images to get more information and example R codes for each of the line plots.

Line Plot Resources: Find some further resources on the creation of line plots below.

  • How to Draw a Line Plot in R
  • The plot() Function in R
  • Smooth Scatterplots with lowess Smoothing Function
  • Draw Cumulative Sum in Scatterplot

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (27)

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

Histogram Resources: Find some further resources on the creation of histograms below.

  • How to Create a Histogram in Base R (hist Function)
  • How to Create a Histogram with the ggplot2 Package in R (geom_histogram Function)
  • Draw Multiple Overlaid Histograms with ggplot2 Package in R

Histogram Video Tutorial: The following video shows a tutorial on creating histograms in R.

Pairs Plot

Pairs Plot Definition: A pairs plot is a plot matrix, consisting of scatterplots for each variable-combination of a data frame.

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

pairs(data.frame(x, y)) # Draw pairs plot in R

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (35)

Advanced Pairs Plots: Find some advanced pairs plots below. Click on the images to get more information and example R codes for each of the pairs plots.

Pairs Plot Resources: Find some further resources on the creation of pairs plots below.

Polygon Plot

Polygon Plot Definition: A polygon plot displays a plane geometric figure (i.e. a polygon) within the plot.

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

plot(1, 1, # Draw polygon plot in R col = "white", xlab = "X", ylab = "Y")polygon(x = c(0.7, 1.3, 1.3, 0.8), y = c(0.6, 1.0, 1.4, 1.3), col = "#353436")

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (38)

Advanced Polygon Plots: Find some advanced polygon plots below. Click on the images to get more information and example R codes for each of the polygon plots.

Polygon Plot Resources: Find some further resources on the creation of polygon plots below.

  • polygon Function in R

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (43)

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

QQplot Resources: Find some further resources on the creation of QQplots below.

  • Create a Quantile-Quantile Plot in R
  • The quantile Function in R

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

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (46)

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.

  • How to Draw a Scatterplot in R
  • The plot() Function in R
  • Plot of Empirical Cumulative Distribution Function

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 packagelibrary("VennDiagram") # Load VennDiagram packageplot.new() # Draw empty plotdraw.single.venn(area = 10) # Draw venn diagram

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (53)

Advanced Venn Diagrams: Find some advanced venn diagrams below. Click on the images to get further information and example R codes for each of the venn diagrams.

Venn Diagram Resources: Find some further resources on the creation of venn diagrams below.

  • How to Create a Venn Diagram in R

Venn Diagram Video Tutorial: The following video shows a tutorial on creating venn diagrams in R.

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

3D Plot of PCA in R (2 Examples)

3D plotly Graph in R (3 Examples)

abline Function in R (6 Examples)

Add Arrow to Plot in R (2 Examples)

Add Axes to Plot Using axis Function in R (4 Examples)

Add Color Between Two Points of Kernel Density Plot in R (Example)

Add Diagonal Line to Plot in R (2 Examples)

Load More

ggplot2

I have created a detailed introduction to the ggplot2 package, which explains the basic concepts of this library in more detail. You can find the introduction here.

Furthermore, you might have a look at the following list of ggplot2 tutorials, in case you are eager to learn more about certain components of the package.

Add Arrow to Plot in R (2 Examples)

Add Color to Region Between Two Lines in ggplot2 Line Plot in R (2 Examples)

Add Common Legend to Combined ggplot2 Plots in R (Example)

Add Confidence Band to ggplot2 Plot in R (Example)

Add Count Labels on Top of ggplot2 Barchart in R (Example)

Add Diagonal Line to Plot in R (2 Examples)

Add Different Line to Each Facet of ggplot2 Plot in R (Example)

Add Fitted Line within Certain Range to Plot in R (2 Examples)

Load More

Learn More About Plots in R

This tutorial showed an overview of many different graphics and plots of the R programming language. If you are keen 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 would like 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…

  • List of Useful R Functions (+ Examples)

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

  • The R Programming Language

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!

19 Comments. Leave new

  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (75)

    Jan Schäfer

    August 31, 2020 7:12 am

    Thanks for the comprehensive introduction into plots!

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (76)

      Joachim

      August 31, 2020 7:14 am

      Hi Jan,

      Thanks for the kind words, glad to hear that you liked the introduction!

      Regards,

      Joachim

      Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (77)

    Abdoulaye Sarr

    May 22, 2021 1:21 pm

    any example on point data on a geographic (country or region ) map. Example temperature or precipitation

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (78)

      Joachim

      May 25, 2021 6:45 am

      Hey Abdoulaye,

      I do not have such examples yet, but I’ll put it on my to-do list.

      Regards

      Joachim

      Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (79)

    Dr.D.K.Samuel

    June 6, 2021 11:57 am

    Extremely useful. Thanks. Will you consider making a tutorial for gganimate please

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (80)

      Joachim

      June 7, 2021 6:03 am

      Hey,

      Thanks a lot for the very nice feedback! Yes, this is definitely planned for the future. I’ll keep you updated.

      Regards

      Joachim

      Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (81)

    Mohammad Sarfraz

    June 26, 2021 5:15 am

    Thank a lot Mr Jaochim, very useful and easy to understand ,it will be very helpful if you add tutorial on time series models ,like GARCh,ARIMA ….
    Thanks and regards

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (82)

      Joachim

      June 26, 2021 6:55 am

      Hey Mohammad,

      Thanks a lot for the kind words!

      I have definitely planned to publish more tutorials on time series data in the future. I hope I’ll find the time for it soon 🙂

      Regards

      Joachim

      Reply
      • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (83)

        Rotem

        June 29, 2021 9:37 am

        Looking foreward to it 🙂

        Reply
        • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (84)

          Joachim

          June 29, 2021 11:56 am

          I’ll keep you updated! 🙂

          Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (85)

    smlknk

    January 17, 2022 11:07 am

    Lad X være som givet ovenfor. Implement´er likelihood funktionen λ 7→ L(λ; 3) i R. Plot funktionen i intervallet [0, 6] og indtegn en lodret streg ved λ = λˆML.
    please help

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (86)

      Joachim

      January 17, 2022 1:16 pm

      Hey,

      Please ask your question in English and share the code you have tried yourself 🙂

      Regards,
      Joachim

      Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (87)

    Saima

    February 21, 2023 12:33 pm

    I would like to plot both a histogram for observed data and a fitted Weibull function on the same graph. Can u plz help me?

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (88)

      Cansu (Statistics Globe)

      February 22, 2023 9:26 am

      Hello Saima,

      I think you can adapt our Overlay Normal Density Curve on Top of ggplot2 Histogram in R tutorial to implement what you want. It is possible that you use the dweibull function instead of dnorm.

      Regards,
      Cansu

      Reply
      • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (89)

        Saima

        March 5, 2023 4:24 am

        Thanks, Cansu.

        Reply
  • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (90)

    Saima

    March 6, 2023 10:31 am

    I used the following code.
    data <- data.frame(x = c(4, 5, 6, 8, 35, 1,23, 4, 3, 27, 3,1, 1, 2, 3,4 ))
    head(data) # Print head of example data

    ggplot(data, aes(x)) + # Draw histogram with density
    geom_histogram(aes(y = ..density..)) +
    stat_function(fun = dweibull,
    args = list(mean = mean(data$x),
    sd = sd(data$x)),
    col = "#1b98e0",
    size = 5)
    But I only get the histogram. I don't get the PDF with it.

    Reply
    • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (91)

      Cansu (Statistics Globe)

      March 7, 2023 10:18 am

      Hello Saima,

      Apparently, the arguments that you should use are shape and scale when it comes to Weibull. They are something to do with the slope and stretch of the curve, see here. Reminding that you should change the inputs of the arguments, you can adapt the following code:

      ggplot(data, aes(x)) + # Draw histogram with density geom_histogram(aes(y = ..density..)) + stat_function(fun = dweibull, args = list(shape = mean(data$x), scale = sd(data$x)), col = "#1b98e0", size = 5)

      For further info on plotting continuous distributions via ggplot2, see this.

      Regards,
      Cansu

      Reply
      • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (92)

        Saima

        March 7, 2023 10:29 am

        I don’t know how to thank you. You are such a wonderful guy. Many thanks.

        Reply
        • All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (93)

          Cansu (Statistics Globe)

          March 7, 2023 11:00 am

          Hello Saima,

          Also, many thanks from my side. Keep it up!

          Regards,
          Cansu

          Reply

Leave a Reply

All Graphics in R (Gallery) | Plot, Graph, Chart, Diagram, Figure Examples (2024)

FAQs

What are the different types of graphics that can be created in R? ›

There are many functions in base R for making different kinds of plots, including hist() , plot() , boxplot() , dotchart() , barchart() , and mosaicplot() to make, respectively, a histogram, scatter plot, box plot, dot chart, bar chart, and mosaic plot.

What are the 4 basic graphs used for representation in R? ›

R has a number of built-in tools for basic graph types such as histograms, scatter plots, bar charts, boxplots and much more. Rather than going through all of different types, we will focus on plot() , a generic function for plotting x-y data.

What is ggplot in R with example? ›

ggplot is a popular data visualization package in R programming. It stands for “Grammar of Graphics plot” and is based on the grammar of graphics concept, which provides a consistent and structured way to create visualizations.

How to make good graphs in R? ›

To customize your graphs, here are some of the most common base R functions:
  1. Add a graph title: main = "Title of Graph"
  2. Add x-axis label: xlab = "X-axis Name"
  3. Add y-axis label: ylab = "Y-axis Name"
  4. Rotate the label horizontal to the axis (Label of Axis Style): las = 1.
  5. Rotate the label perpendicular to the axis: las = 2.
Apr 16, 2024

What are the three basic types of graphics? ›

Three of the primary types of graphics include drawings, computer-generated imagery (CGI), and digital graphics. Drawings, which can be created by hand or through the use of digital tools, are used in a wide variety of applications, including to illustrate stories or clarify educational concepts.

What are the 2 different types of graphics? ›

There are two types of computer graphics: raster graphics, where each pixel is separately defined (as in a digital photograph), and vector graphics, where mathematical formulas are used to draw lines and shapes, which are then interpreted at the viewer's end to produce the graphic.

What is a R graph gallery? ›

Welcome the R graph gallery, a collection of charts made with the R programming language. Hundreds of charts are displayed in several sections, always with their reproducible code available. The gallery makes a focus on the tidyverse and ggplot2.

How many graphs are there in R? ›

There are hundreds of charts and graphs present in R. For example, bar plot, box plot, mosaic plot, dot chart, coplot, histogram, pie chart, scatter graph, etc.

What types of plots can be made in R using ggplot? ›

In this lesson, you will focus on using ggplot2 to create four types of graphs: a histogram, a scatter plot, a bar plot, and a box plot. However, you can create numerous other types of graphs in ggplot2, such as density plots, box plots, violin plots, maps, and much more.

What is the difference between plot and ggplot in R? ›

Plotly is the second most popular visualization package in R after ggplot2. Whereas ggplot2 is used for static plots, plotly is used for creating dynamic plots. Similarly, it offers a plethora of options in terms of chart type we can visualize our data with.

What are the three plotting systems in R? ›

Watch a video of this chapter. There are three different plotting systems in R and they each have different characteristics and modes of operation. They three systems are the base plotting system, the lattice system, and the ggplot2 system. This chapter (and this book) will focus primarily on the base plotting system.

How do you draw a line on a graph in R? ›

The R function abline() can be used to add vertical, horizontal or regression lines to a graph. A simplified format of the abline() function is : abline(a=NULL, b=NULL, h=NULL, v=NULL, ...)

What are the standard graphics in R? ›

The most commonly used graphs in the R language are scattered plots, box plots, line graphs, pie charts, histograms, and bar charts. R graphs support both two dimensional and three-dimensional plots for exploratory data analysis.

What are the different types of graphs in Rstudio? ›

With R, users can create simple charts such as pie, bar, and line graphs to more sophisticated plots like scatter plots, box plots, heat maps, and histograms.

What are graphic devices in R? ›

Graphics in R are plotted on a graphics device. You can manually specify a graphics device or let R use the default device. In an interactive R environment, the default is to use the device that plots graphics on the screen. On Microsoft Windows, the windows device is used.

What are the different types of system graphics? ›

Types of Computer Graphics
  • Raster Graphics: In raster, graphics pixels are used for an image to be drawn. ...
  • Vector Graphics: In vector graphics, mathematical formulae are used to draw different types of shapes, lines, objects, and so on.
Jun 24, 2024

What are the different types of graphics processing? ›

GPUs come in two basic types: integrated and discrete. An integrated GPU does not come on its own separate card at all and is instead embedded alongside the CPU. A discrete GPU is a distinct chip that is mounted on its own circuit board and is typically attached to a PCI Express slot.

Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5533

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.