Relationship Numerical

Scatter Plot

ggplot2: geom_point() · Package: ggplot2 · Variables: 2 numerical

WHAT IS A SCATTER PLOT?

A scatter plot (also called a scatter diagram or XY plot) places individual data points on two axes to reveal the relationship between two continuous variables. It is the go-to chart for answering "is there a correlation between X and Y?" Scatter plots reveal patterns like positive/negative correlations, clusters, and outliers that are invisible in summary statistics. Add a trend line with geom_smooth() to highlight the overall pattern. Color or shape aesthetics can encode a third variable (categorical grouping). Scatter plots require at least 10-15 data points to show meaningful patterns.

HOW TO READ A SCATTER PLOT

A scatter plot shows the joint distribution of two continuous variables, and the shape of the cloud is the message. An upward drift means the variables rise together; a downward one means they trade off; a shapeless blob means neither predicts the other. Look past the overall direction for structure the correlation coefficient will not report: separate clusters suggesting a hidden grouping variable, a curved band indicating a non-linear relationship that a straight-line fit would misrepresent, a funnel widening to the right showing variance that grows with the level. Points far from the mass are worth investigating individually before deciding whether they are errors or the most interesting observations in the dataset. Remember throughout that association is not causation, and that a single influential outlier can create or destroy an apparent relationship.

BEST FOR

  • · Correlation analysis
  • · Identifying clusters
  • · Detecting outliers
  • · Bivariate exploration

AVOID WHEN

  • · Categorical data on either axis
  • · Fewer than 10 data points
  • · Time-series trend

R + GGPLOT2 CODE EXAMPLE

ggplot2
ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(color = "#ff6a00", size = 2) +
  labs(title = "Weight vs MPG", x = "Weight (1000 lbs)", y = "MPG")

GROUPED SCATTER WITH A SMOOTHER AND MARGINAL CONTEXT

Colour by a grouping variable, one smoother per group, and alpha set for overplotting — the exploratory form that shows whether a relationship holds within groups as well as overall.

ggplot2
library(ggplot2)

ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl))) +
  geom_point(alpha = 0.75, size = 2.5) +
  geom_smooth(method = "lm", se = FALSE, linewidth = 0.7) +
  scale_colour_manual(
    values = c("4" = "#ff6a00", "6" = "#3d9970", "8" = "#7d5fff"),
    name = "Cylinders"
  ) +
  labs(
    title = "Weight vs fuel economy, by engine size",
    subtitle = "The negative relationship holds within every group",
    x = "Weight (1000 lbs)", y = "Miles per gallon"
  ) +
  theme_minimal(base_size = 12)

# For tens of thousands of points, bin instead of plotting each one:
# ggplot(big_df, aes(x, y)) + geom_hex(bins = 50)

COMMON MISTAKES WITH THIS CHART

Overplotting hiding the density

With thousands of points the middle saturates and structure disappears. Use geom_point(alpha = 0.2), or switch to geom_hex() or geom_bin2d() where the count itself becomes the encoding.

Adding a straight trend line to a curved relationship

geom_smooth(method = "lm") always draws a straight line, even where the data bends. Look at the default loess smoother first and only impose a linear fit once you have seen the shape.

Plotting rounded or discrete values without jitter

Values rounded to whole numbers stack into a lattice and hide how many observations sit at each position. geom_jitter(width = 0.2) separates them.

Treating the correlation coefficient as the whole story

Anscombe's quartet has four datasets with identical correlations and completely different shapes. Always look at the plot before quoting r.

Run this code now

Paste the code above into RChat and see the scatter plot rendered instantly in your browser.

Try RChat Free →

SIMILAR CHART TYPES

ALTERNATIVES FOR YOUR DATA TYPE