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







