Basic scatterplot with R and ggplot2

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

Scatter Section About Scatter

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.

# library
# The iris dataset is provided natively by R
# basic scatterplot
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + 

Related chart types

Connected scatter
Density 2d


This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message on Twitter, or send an email pasting with

Github Twitter