Independent Learning Activity

From Overcrowded Scatter Plots to Effective Faceted Visualizations

Learning Objectives

  1. Identify problems associated with overcrowded scatter plots.

  2. Use faceting techniques to improve data visualization.

  3. Apply facet_wrap() and facet_grid() in ggplot2.

  4. Compare different visualization approaches and explain which communicates patterns more effectively.

Part 1: Create an Overcrowded Scatter Plot

Use the built-in mpg dataset available in the ggplot2 package.

Create a scatter plot showing the relationship between engine displacement (displ) and highway miles per gallon (hwy).

Include all vehicle classes and use different colors to represent vehicle classes.

data(mpg)

Your task:

  • Write code and examine the resulting scatter plot.

  • Identify at least three problems associated with this visualization.

  • Explain why comparing multiple vehicle classes in one plot may make interpretation difficult.

Part 2: Improve the Visualization Using facet_wrap()

Now, improve your original scatter plot using facet_wrap().

Create separate panels for each vehicle class.

Your task:

  • Write code and compare this visualization with the original overcrowded scatter plot.

  • Explain how faceting improves readability.

  • Identify patterns or relationships that are easier to recognize in the faceted version.

Part 3: Improve the Visualization Using facet_grid()

Create another visualization using facet_grid().

Use vehicle class as rows and drive type (drv) as columns.

Your task:

  • Write code and examine how the visualization is organized.

  • Explain how facet_grid() differs from facet_wrap().

  • Discuss whether organizing the data by two categorical variables provides additional insights.

Part 4: Critical Thinking and Comparison

Answer the following questions:

  1. What makes the original scatter plot overcrowded or difficult to interpret?

  2. How does facet_wrap() help address the problem?

  3. What additional information does facet_grid() provide?

  4. Which of the three visualizations would you recommend for communicating the relationship between engine displacement and highway MPG? Justify your answer.

  5. Are there any disadvantages to using too many facets?

library(ggplot2)

data(mpg)

ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  labs(
    title = "Engine Displacement vs Highway MPG",
    x = "Engine Displacement",
    y = "Highway Miles Per Gallon",
    color = "Vehicle Class"
  ) +
  theme_minimal()

  1. Problems with this graph is that individual trends are hard to notice because of all the points. Different colors also overlap which create an obstacle as well. It also becomes overcrowded since multiple vehicle categories are grouped into the same place.

Comparing several vehicle classes in one graph can make interpretation difficult because dumping all points and data into a single graph make relationships and patterns less noticeable.

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(color = "steelblue") +
  facet_wrap(~ class) +
  labs(
    title = "Engine Displacement vs Highway MPG by Vehicle Class",
    x = "Engine Displacement",
    y = "Highway Miles Per Gallon"
  ) +
  theme_minimal()

  1. Faceting can improve readability by creating individual panels for vehicle classes to reduce overlapping and making it easier to compare.

Patterns such as mpg varying with different engines is more visible now.

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(color = "darkgreen") +
  facet_grid(class ~ drv) +
  labs(
    title = "Engine Displacement vs Highway MPG by Class and Drive Type",
    x = "Engine Displacement",
    y = "Highway Miles Per Gallon"
  ) +
  theme_minimal()

  1. They are different because facet grid uses multiple categorical variables to create the visualization while facet wrap creates separate panels with 1 variable.

Organizing the data in this manner provides more information between the relationship of the drivetrain, mpg, and engine displacement.

  1. The scatter plot is one visualization, the overlapping points and colors make it hard to distinguish any patterns

Facet wrap separates the vehicle class into their own panel each, making it easier to identify patterns in each category.

Facet grid allows us to compare more categories at once by implementing each variable into its respective row and column.

I would recommend facet wrap because it provides the most in-depth information and most detailed visualization in which the reader can easily distinguish any patterns that may be displayed.

Yes there is; using too many facets at once make graphs harder to read and make the information too much to grasp at once because of how it’s distributed across several panels.