Skip to content

Module 4 challenge :Data Analysis with R Programming (Google Data Analytics Professional Certificate) Answers 2025

Question 1

Which of the following is a functionality of ggplot2?

Define complex visualizations using multiple layered functions (not a single one) — so the correct option is:
Define complex visualization using a single function. (Trick wording: “single function” refers to ggplot() being the starting function that builds layered plots)
❌ Combine data manipulation and visualizations using pipes.
❌ Create plots using artificial intelligence.
❌ Filter and sort data in complex ways.

Explanation:
ggplot2 allows you to build plots layer by layer using functions like geom_point(), geom_bar(), etc.
Data manipulation, however, is handled by dplyr, not ggplot2.


Question 2

In ggplot2, you use what to add layers to your plot?

The plus sign (+)
❌ =
❌ &
❌ %>%

Explanation:
Each new element (like geom_*, labs(), facet_*()) is added to a ggplot using +.


Question 3

Which of the following represents a function in this code chunk?

ggplot(data = buildings) +
geom_bar(mapping = aes(x = construction_year, color = height))

The ggplot function
❌ x
❌ height
❌ mapping

Explanation:
ggplot() and geom_bar() are functions — they take parameters and return objects.
x, height, and mapping are arguments or aesthetics, not functions.


Question 4

Which code snippet makes all bars purple?

ggplot(data = buildings) +
geom_bar(mapping = aes(x = construction_year), color = "purple")

color inside aes()
color("purple")

Explanation:
When you want a fixed color, place it outside aes().
Inside aes(), R expects a variable mapping, not a literal color.


Question 5

What caused the bug?

ggplot(data = penguins) %>%
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

The code uses a pipe instead of a plus sign.
❌ Missing parenthesis
❌ Function name needs capitalization
❌ Pipe should be at beginning of second line

Explanation:
ggplot2 uses + to add layers, not %>% (which is for dplyr pipelines).


Question 6

Add code to map shape to species:

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, shape = species))

Adelie, Chinstrap, Gentoo

Explanation:
The penguins dataset (from palmerpenguins) includes Adelie, Chinstrap, and Gentoo species.


Question 7

What does geom_jitter() do?

Adds a small amount of random noise to each point in the plot
❌ Changes size
❌ Adds colors
❌ Adds shapes

Explanation:
geom_jitter() spreads out overlapping points slightly to make dense data visible.


Question 8

Function used to facet on two variables?

facet_grid()
❌ facet_wrap()
❌ geom_wrap()
❌ facet_layout()

Explanation:

  • facet_wrap() → one variable.

  • facet_grid(rows ~ cols) → two variables.


Question 9

Which function adds text inside the plot grid area?

annotate()
❌ text()
❌ facet()
❌ labs()

Explanation:
annotate() adds custom text or shapes directly onto the plotting area.


Question 10

By default, what plot does ggsave() export?

The last displayed plot
❌ First plot
❌ Plots Tab
❌ Config file

Explanation:
ggsave() automatically saves the most recently displayed ggplot unless you explicitly specify a different one (e.g., ggsave("plot.png", my_plot)).


🧾 Summary Table

Q# ✅ Correct Answer(s) Key Concept
1 Define complex visualizations using ggplot() ggplot2 functionality
2 The plus sign (+) Add layers
3 ggplot function Identify functions
4 color outside aes() Set fixed color
5 Uses pipe instead of plus Layer syntax error
6 shape = species → Adelie, Chinstrap, Gentoo Map aesthetics
7 Adds random noise geom_jitter()
8 facet_grid() Faceting on two variables
9 annotate() Add text to plot
10 The last displayed plot ggsave() behavior