Scatter Plots

Explore the features of scatter plots and learn how to create them.

Features

Scatter plots show data points on a chart by crossing at least two features of an element.

Scatter plots show the relationship between two variables, each represented on different axes. We can identify trends, correlations, and outliers by looking at the scatter plots. We do not prefer scatter plots when two datasets are not related.

Press + to interact
Scatter plot
Scatter plot

Scatter plot with plot()

The built-in function plot() generates scatter plots in R. It takes at least two variables that contain the data to be represented. We define the variables as x and y.

# Syntax structure
plot(x = <variable1>, y = <variable2>)

Let’s create a simple scatter plot using the mtcars dataset.

Press + to interact
# We use the `mtcars` dataset in this exercise
head(mtcars) # Preview of the dataset
plot(x = mtcars$mpg, y = mtcars$disp) # Define the variables in the function.
  • Line 3: The data in the mpg column is reflected on the x axis, and disp is reflected on the y axis.

We can state that the data in these columns are negatively correlated because as mpg increases, disp decreases.

We can configure the chart using the following arguments:

  • col: This changes the colors of the points on the chart. This argument ...