Basic scatterplot


This post provides reproducible code and explanation for the most basic scatterplot you can build with ggplot2.

A scatterplot displays the values of two variables along two axes. It shows the relationship between them, eventually revealing a correlation.

Here the relationship between Sepal width and Sepal length of several plants is shown.

It illustrates the basic utilization of ggplot2 for scatterplots:

  • 1 - provide a dataframe
  • 2 - tell which variable to show on x and y axis
  • 3 - add a geom_point() to show points.
# Libraries
library(ggplot2)
 
# Basic scatterplot
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + 
    geom_point() + theme_bw()




Contact

This document is a work of the statistics team in the Biostatistics and Medical Information Department at Saint-Louis Hospital in Paris (SBIM).
Developed and updated by Noémie Bigot and Anouk Walter-Petrich
noemie.bigot@aphp.fr; anouk.walter-petrich@u-paris.fr

Based on The R Graph Gallery by Yan Holtz.

SBIM