liveBook · Manning

Scatter plot

As explained in Statistics Slam Dunk

A scatterplot displays observations as points positioned by the values of two variables, or by one variable against an index or sequence.

A scatter plot displays observations as points positioned by two variables, or by one variable against an index or sequence. In exploratory data analysis, it offers a visual way to inspect a variable and look for possible outliers. section 5.4.1

Use a scatter plot to:

  • Inspect the values of a single variable by plotting it against evenly spaced positions created with seq_along(). section 5.4.1
  • Look for unusual observations before applying statistical outlier tests such as Dixon’s Q Test or Grubbs’ Test. section 5.4.1
  • Distinguish this indexed display from a correlation plot, which visualizes the relationship between paired x- and y-axis variables. section 5.4.1

Plotting deflections

With the hustle data set, qplot(seq_along(hustle$deflections), hustle$deflections) creates a scatter plot of deflections against observation order. Labels and annotations can flag values for inspection. The visual may not make outliers obvious, so compare it with a histogram and boxplot; boxplots provide a less subjective indication through points beyond the whiskers. section 5.4.1

sp1 <- qplot(seq_along(hustle$deflections), hustle$deflections) +
 labs(title = "Deflections", 
      subtitle = "scatterplot", 
      x = "", 
      y = "Value") +
 theme(plot.title = element_text(face = "bold")) +
 annotate("text", x = 65, y = 18.5, 
          label = "Outlier?", color = "red",
          size = 3, fontface = "bold") +
 annotate("text", x = 85, y = 18.3, 
          label = "Outlier?", color = "red",
          size = 3, fontface = "bold") 

hist1 <- ggplot(hustle, aes(x = deflections)) + 
 geom_histogram(fill = "snow1", color = "dodgerblue4", bins = 8) + 
 labs(title  ="Deflections", 
      subtitle = "histogram",
      x = "",           
      y  = "Frequency") +
 theme(plot.title = element_text(face = "bold")) +
 annotate("text", x = 18.75, y = 3, 
          label = "  Outliers?", color = "red",
          size = 3, fontface = "bold") 

bp1 <- ggplot(hustle, aes(x = "", y = deflections)) + 
 labs(title = "Deflections", 
      subtitle = "boxplot", 
      x = "", 
      y = "") +
 geom_boxplot(color = "dodgerblue4", fill = "snow1", width = 0.5) +
 stat_summary(fun = mean, geom = "point", shape = 20, size = 8,
              color = "dodgerblue4", fill = "dodgerblue4") + 
 annotate("text", x = "", y = 18.6, 
          label = "                  Outliers",
          color = "red", size = 3, fontface = "bold") +
 theme(plot.title = element_text(face = "bold"))

The runnable listing builds and labels the deflections scatter plot, then annotates observations that might be outliers. section 5.4.1

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates R construction and interpretation, but stops short of making visual outlier identification definitive.
Examples
Uses hustle deflections, indexed observation positions, annotations, and side-by-side histogram and boxplot comparisons.
What you can do after
Apply it via R’s qplot to inspect a variable and compare suspected outliers with other visualizations.
How it connects
Connects scatter plots with outliers, histograms, boxplots, correlation plots, and exploratory data analysis.

Also explained in

Compare how 8 books explain scatter plot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.