Week 4 – More about visualizations, aesthetics, and annotations

data analysis with r programming weekly challenge 4

1. Which of the following are benefits of using ggplot2? Select all that apply.

  • Customize the look and feel of your plot
  • Easily add layers to your plot
  • Combine data manipulation and visualization
  • Automatically clean data before creating a plot

 

2. A data analyst creates a bar chart with the diamonds dataset. They begin with the following line of code:

ggplot(data = diamonds)

What symbol should the analyst put at the end of the line of code to add a layer to the plot?

  • pipe operator (%>%)
  • plus sign (+)
  • equal sign (=)
  • ampersand symbol (&)

 

3. A data analyst creates a plot using the following code chunk:

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

Which of the following represents a function in the code chunk? Select all that apply.

  • The aes function
  • The geom_point function
  • the data function
  • The ggplot function

 

4. Fill in the blank: In ggplot2, the term mapping refers to the connection between variables and _____ .

  • data frames
  • geoms
  • facets
  • aesthetics

5. A data analyst creates a scatterplot with a lot of data points. The analyst wants to make some points on the plot more transparent than others. What aesthetic should the analyst use?

  • Color
  • Shape
  • Alpha
  • Fill

 

6. You are working with the penguins dataset. You create a scatterplot with the following code:

ggplot(data = penguins) +

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

You want to highlight the different penguin species on your plot. Add a code chunk to the second line of code to map the aesthetic shape to the variable species.

NOTE: the three dots (...) indicate where to add the code chunk.

Which penguin species does your visualization display?

  • Adelie, Chinstrap, Gentoo
  • Emperor, Chinstrap, Gentoo
  • Adelie, Chinstrap, Emperor
  • Adelie, Gentoo, Macaroni

 

7. A data analyst creates a plot with the following code chunk:

ggplot(data = penguins) +

geom_jitter(mapping = aes(x = flipper_length_mm, y = body_mass_g))

What does the geom_jitter() function do to the points in the plot?

  • Adds a small amount of random shapes at each point in the plot
  • Decrease the size of each point in the plot
  • Adds a small amount of random noise to each point in the plot
  • Adds random colors to each point in the plot

 

8. You are working with the diamonds dataset. You create a bar chart with the following code:

ggplot(data = diamonds) +

geom_bar(mapping = aes(x = color, fill = cut)) +

You want to use the facet_wrap() function to display subsets of your data. Add the code chunk that lets you facet your plot based on the variable clarity.

How many subplots does your visualization show?

  • 9
  • 6
  • 8
  • 7

9. Fill in the blank: You can use the _____ function to put a text label on your plot to call out specific data points.

  • annotate()
  • ggplot()
  • facet_grid() 
  • geom_smooth()

10. You are working with the penguins dataset. You create a scatterplot with the following lines of code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g)) +

What code chunk do you add to the third line to save your plot as a png file with “penguins” as the file name?

  • ggsave(“penguins”)
  • ggsave(penguins.png)
  • ggsave(“png.penguins”)
  • ggsave(“penguins.png”)

 

Shuffle Q/A 1

11. In ggplot2, what symbol do you use to add layers to your plot?

  • The pipe operator (%>%)
  • The plus sign (+)
  • The ampersand symbol (&)
  • The equals sign (=)

12. A data analyst creates a plot using the following code chunk:

ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color = height))

Which of the following represents an aesthetic attribute in the code chunk?

  • ggplot
  • construction_year
  • buildings
  • x

Devendra Kumar

Project Management Apprentice at Google

Leave a Reply