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.

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.

library(ggplot2)
data(mpg)

# Creating scatterplot
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
         geom_point() +
  labs(
    title = "Highway MPG vs. Engine Displacement by Vehicle Class",
    x = "Engine Displacement",
    y = "Highway MPG",
    color = "Vehicle Class"
  )

Answer: 1. Multiple Observations mixed directly on top of each other 2. I think the colors are also difficult to figure out between the legends. 3. There is no trend line to show the pattern

Part 2: Improve the Visualization Using facet_wrap()

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

Create separate panels for each vehicle class.

ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  facet_wrap(~ class) +
  labs(
    title = "Highway MPG vs. Engine Displacement by Vehicle Class",
    x = "Engine Displacement",
    y = "Highway MPG",
    color = "Vehicle Class"
  ) +
  theme_minimal() +
  theme(legend.position = "none")

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.

Answer: This facet_wrap() function creates different side by side panels according to the class, which is easier to view. It does not evem need legend and color code to check the class. Every car of its class is generated in separate plot. It looks much cleaner than the first scatter-plot.

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.

ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  facet_grid(class ~ drv) +
  labs(
    title = "Highway MPG vs. Engine Displacement by Class and Drive Type",
    x = "Engine Displacement",
    y = "Highway MPG",
  ) +
  theme_minimal() +
  theme(legend.position = "none")

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.

Answer: Each classes have its own row, that is easier to view. It creates 3 vertical columns based on the “drv” variable. It also has class variable in the right side of the each data. In facet_grid, it keeps every cell in the grid, even if a box is empty however, facet_wrap would skip combinations with no data.

Part 4: Critical Thinking and Comparison

Answer the following questions:

  1. What makes the original scatter plot overcrowded or difficult to interpret? Answer: Multiple Observations mixed together. Colors are also similar and hard to find out. Lack of trend line to show the pattern.

  2. How does facet_wrap() help address the problem? Answer: It separates classes into different clean plot, and reduces the necessity of legend work

  3. What additional information does facet_grid() provide? Answer: It provides structural gaps and creates rows and columns with relative variables.

  4. Which of the three visualizations would you recommend for communicating the relationship between engine displacement and highway MPG? Justify your answer. Answer: I would choose the facet_wrap because it is easier to view and creates different plots according to the variables. I found facet_grid shows empty cell. Facet_wrap is generally good to check the data.

  5. Are there any disadvantages to using too many facets? Answer: It makes points harder to view than in normal. Too many facets lead to empty cell with no meaning. It creates difficulty to check and read data.