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)
library(ggplot2)
data(mpg)

ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point() +
  labs(x = "Engine displacement",
        y = "Highway miles",
       title = "Engine Displacement vs. Highway Fuel by Vehicle Class",
       color = "Vehicle class")

Your task:

  • Write code and examine the resulting scatter plot.

  • Identify at least three problems associated with this visualization.

    Some points may overlap, it may not show every observation which leads to some vehicle classes possibly unrepresented, and it’s very crowded.

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

    There are seven different vehicle classes and it’s put on a stacked grid, so the final visualization looks very crowded and it’s hard to see what trend is going on in the graph.

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() +
  labs(x = "Engine displacement",
       y = "Highway miles",
       title = "Engine Displacement vs. Highway Fuel by Vehicle Class",
       color = "Vehicle class") +
  facet_wrap(~ class)

Your task:

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

  • Explain how faceting improves readability.

    Facet_wrap() splits the original visualization into seven different plots, and each plot shows the vehicle class, but without all the other classes. This allows us to look closer at what is happening because now the data isn’t overlapping or crowding.

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

    I can now see that SUVs has a large range of engine displacement, but the highway miles are all less than 30, pickups show a similar pattern as well. I can also see that compact and subcompact vehicles have lower engine displacement, but higher highway miles.

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() +
  labs(x = "Engine displacement",
       y = "Highway miles",
       title = "Engine Displacement vs. Highway Fuel by Vehicle Class and Drive Type",
       color = "Vehicle class") +
  facet_grid(class ~ drv)

Your task:

  • Write code and examine how the visualization is organized.

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

    Facet_wrap() puts the data into different plots based on one variable. Facet_grid does the same, but it also adds another variable and creates new plots with the condition of the new variable, if that combination doesn’t exist, the plot is empty.

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

    Yes, because through this we can see that which kind of car has what kind of drive type, and how it could affect highway miles. We can clearly see that there are no front-wheel pickups and four-wheel vehicles have higher highway miles.

Part 4: Critical Thinking and Comparison

Answer the following questions:

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

    All observations and vehicle classes are forced into a single grid, making it look crowded and incomplete. Some cars may share the same characterisitics, so it can also hide some observations.

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

    Facet_wrap() separated the graph and we were able to see each vehicle class and the relationship between engine displacement and highway miles for each class.

  3. What additional information does facet_grid() provide?

    Facet_grid() lets us add another variable and we can see how drive type affects highway miles and engine displacement. The blank plots also show us what combinations do not exist in the dataset.

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

    I recommend the facet_wrap() graph because the first visualization was too crowded, and the facet_grid() plots could get confusing and overwhelming, but the facet_wrap() plots give a lot of information, isn’t cluttered, and isn’t overwhelming or hard to read.

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

Each plot gets smaller with every additional variable and this makes the dots, at some point, unreadable. It also spreads the data out a lot and makes it harder to connect the plots together and find trends.