Week 4: More About Visualization, Aesthetics, and Annotations
More About Visualization, Aesthetics, and Annotations INTRODUCTION
This is a section you need to complete for the Coursera Google Data Analytics Professional Certification. It involves some knowledge and training in the visualization of data using R. Learn how to produce and troubleshoot visualizations in R. Find out how RStudio features will allow you to beautify your charts, including styles for annotating and saving them. By the time you complete this module, you’ll be able to create sophisticated visualizations which are not only shareable but also easily fit into presentations.
Working with R can seem pretty scary at the start, but with enough practice and applying it, one will take on building some nice looking visualizations quite confidently. It is the most important one in the bag of any data analyst and a good benefit in dealing with complex data.
Learning Outcomes:
- Discover the aesthetics attributes in R: size, shape, color, and plots.
- Identify and describe common visualization problems in R.
- Use ggplot() for the generation of very basic visuals.
- List the options for creating visuals in R.
- Illustrate the mechanism of RStudio to save visuals.
- Each ggplot2 will create a plot.
- Define what ggplot2 is about and the basic philosophy behind it; what it is used for.
Test Your Knowledge on Data Visualization in R
1. In ggplot2, you can use the _____ function to specify the data frame to use for your plot.
- geom_point()
- aes()
- labs()
- ggplot() (Correct)
In ggplot2 you can use the _ function to specify the data frame to use for your plot.
Correct: With this important function, ggplot(), the data frame can be incorporated for your plot in ggplot2.
2. In ggplot2, you use the plus sign (+) to add a layer to your plot.
- True (Correct)
- False
Correct: In ggplot2, you add layers to your plot using this plus sign (+).
3. In ggplot2, what function do you use to map variables in your data to visual features of your plot?
- The ggplot() function
- The aes() function (Correct)
- The geom_bar() function
- The geom_point() function
Correct: By the way, the aes() function in ggplot2 assigns aesthetics from your data to the visual aspects of your plot.
4. What type of plot will the following code create?
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
- Boxplot
- Bar chart
- Scatterplot (Correct)
- Line diagram
Correct: In the code a scatterplot will be generated with geom_point() for plotting points using the scatterplot.
Test Your Knowledge on Aesthetics in Analysis
1. Which of the following aesthetics attributes can you map to the data in a scatterplot? Select all that apply.
- Text
- Shape (Correct)
- Size (Correct)
- Color (Correct)
Correct: A scatterplot can be used to represent the data as per the size, shape, color aesthetics to differentiate points according to those attributes in the view.
2. Which of the following functions let you display smaller groups, or subsets, of your data?
- ggplot()
- facet_wrap() (Correct)
- geom_point()
- geom_bar()
Correct: Facet_wrap() enables you to display smaller pieces or groups of your data in multiple panels each showing different subset of that data set.
3. What is the role of the x argument in the following code?
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))
- A function
- An aesthetic (Correct)
- A variable
- A dataset
Correct: The aesthetic x is for the x-axis of the plot itself. In this example, the x aesthetic maps the cut variable from the diamonds dataset to the x-axis of our plot.
4. A data analyst creates a scatterplot with a lot of data points. It is difficult for the analyst to distinguish the individual points on the plot because they overlap. What function could the analyst use to make the points easier to find?
- geom_jitter() (Correct)
- geom_bar()
- geom_line()
- geom_point()
Correct: The analyst can use the geom_jitter() function to make the points easier to distinguish. This function adds a small amount of random noise to each point, thus eliminating the overlap created and making it easier to see them on the plot.
5. You can use this color aesthetic to add color to the outline of each bar in a bar chart.
- True (Correct)
- False
Test Your Knowledge on Annotating and Saving Visualization
1. Which of the following are benefits of adding labels and annotations to your plot? Select all that apply.
- Indicating the main purpose of your plot (Correct)
- Choosing a geom for your plot
- Highlighting important data in your plot (Correct)
- Helping stakeholders quickly understand your plot (Correct)
Correct: Attached to the plot, annotations could offer the advantages of presenting the plot’s main thrust, emphasizing critical data points, and helping the stakeholders develop proper understanding of the point of the plot.
2. A data analyst is creating a plot for a presentation to stakeholders. The analyst wants to add a caption to the plot to help communicate important information. What function could the analyst use?
- The geom_bar() function
- The facet_wrap() function
- The geom_point() function
- The labs() function (Correct)
Correct: Analyst may also use the labs() function to give a caption to the plot and note the further parameters along with the description at which data is being visualised.
3. What function can you use to put a text label inside the grid of your plot to call out specific data points?
- The aes() function
- The annotate() function (Correct)
- The facet_wrap() function
- The labs() function
Correct: The function annotate() helps one to annotate some text within the grid of the graph in order to highlight or call to attention specific data points.
4. 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 use the labs() function to add the title “Penguins” to your plot. Add the code chunk that lets you add the title “Penguins” to your plot.
labs(title = “Penguins”)

Where does your visualization display the title?
- The upper right
- The upper left (Correct)
- The lower right
- The lower left
Correct: In order to insert the title “Penguins” within your plot, use the code chunk labs(title = “Penguins”). Inside the parentheses of the labs() function, indicate the word title, immediately followed by an equal sign, and the necessary title text enclosed by quotation marks. Within the labs() method, you might add any labels to your plot and, it’s important to note that this title will show in the top-left corner of the visualization.
Data Analysis with R Programming Weekly Challenge 4
1. Which of the following tasks can you complete with ggplot2 features? Select all that apply.
- Customize the visual features of a plot (Correct)
- Automatically clean data before creating a plot
- Add labels and annotations to a plot (Correct)
- Create many different types of plots (Correct)
Correct: With ggplot2, there are many ways of making several kinds of plots and modifying each visual element as well as varying telling and annotating the plot to make it much easier to read and interpret.
2. In ggplot2, what symbol do you use to add layers to your plot?
- The pipe operator (%>%)
- The plus sign (+) (Correct)
- The equal sign (=)
- The ampersand symbol (&)
Correct: In ggplot2, you use the plus sign (+) to add layers to your plot.//
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 (Correct)
- The geom_point function (Correct)
- the data function
- The ggplot function (Correct)
Correct: The using functions in this code chunk are ggplot( ), geom_point( ), and aes( ). The basic thing which the ggplot() function does is describe the data frame which carries the plot, whereas the geom_point() describes the point as the geometric object to represent the data. The aes() maps the aesthetic attributes the visibility and definition of plot variables.
4.Fill in the blank: In ggplot2, the term mapping refers to the connection between variables and _____ .
- facets
- geoms
- aesthetics (Correct)
- data frames
Correct: Mapping means linking a certain variable from your dataset with a specific aesthetic in the plot. This is accomplished through aes() function, which specifies that data variable is also assigned aesthetically: color, shape, size, and any other such attributes.
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?
- Alpha (Correct)
- Shape
- Fill
- Color
Correct: The analyst should adopt the alpha aesthetic to adjust the transparency of the points on a plot. Some of these points might be less transparent than the others, which can help denote an overlapping point or improve the visual appearance of the plot.
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.
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, shape = species))

Which penguin species does your visualization display?
- Adelie, Gentoo, Macaroni
- Adelie, Chinstrap, Emperor
- Adelie, Chinstrap, Gentoo (Correct)
- Emperor, Chinstrap, Gentoo
In the aes() function, after specifying the dependent variable y = body_mass_g, add the aesthetic shape and specify its equal sign in the form of the variable species. Consequently, the corresponding data points of the different penguin species will be represented using different shapes: Adelie, Chinstrap, and Gentoo.
7. Fill in the blank: The _____ creates a scatterplot and then adds a small amount of random noise to each point in the plot to make the points easier to find.
- geom_bar() function
- geom_point() function
- geom_jitter() function (Correct)
- geom_smooth() function
Correct: The function geom_jitter() produces a scatter plot, followed by adding a small amount of random interference or jitter to position points. This prevents overplotting where the points have the same or almost the same value and highlights their positions relative to one another. Jitter effects often particularly useful when employing discrete or clustered data.
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 cut.
facet_wrap(~cut)

How many subplots does your visualization show?
- 5 (Correct)
- 3
- 6
- 4
Correct: The visualization created by this code will consist of 5 subplots, each corresponding to a different value of the cut variable. The facet_wrap() function takes in the data and splits it into multiple panels based on the input variable (cut in this case).
9. Fill in the blank: You can use the _____ function to put a text label on your plot to call out specific data points.
- facet_grid()
- annotate() (Correct)
- geom_smooth()
- ggplot()
Correct: If you want to put a text label on your plot, one can make use of the function annotate(). Here’s a code snippet to demonstrate this. The example attaches a text label at a certain coordinate on the plot in concert with a particular data point.
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.png)
- ggsave(“penguins”)
- ggsave(“penguins.png”) (Correct)
- ggsave(“png.penguins”)
Correct: It saves your last plot as a PNG file titled “penguins.png” into your working directory. Your working directory can be specified adding all other parameters like path, width, height, resolution, etc.
11. Which of the following are benefits of using ffplot2? Select all that apply.
- Automatically clean data before creating a plot
- Easily add layers to your plot (Correct)
- Combine data manipulation and visualization (Correct)
- Customize the look and feel of your plot (Correct)
12. A data analyst uses the aes() function to define the connection between their data and the plots in their visualization. What argument is used to refer to matching up a specific variable in your data set with a specific aesthetic?
- Faceting
- Mapping (Correct)
- Jittering
- Annotating
13. A data analyst is working with the penguins data. The analyst creates a scatterplot with the following code:
ggplot (data = penguins) +
geom_point (mapping = aes (x = flipper_length_mm, y = body_mass_g, alpha = species))
What does the alpha aesthetic do to the appearance of the points on the plot?
- Makes some point of the plot more transparent (Correct)
- Makes the points on the plot more colorful
- Makes the points on the plot smaller
- Makes the points on the plot larger
14. 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 color.
facet_wrap(~color)
How many subplots does your visualization show?
- 6
- 8
- 9
- 7 (Correct)
Correct: The code builds a plot demonstrating subparts of data of different color values. The facet_wrap(~color) function creates as many panels as colors and will help compare cut variable within different colors according to their distributions.
15. A data analyst uses the annotate() function to create a text label for a plot. Which attributes of the text can the analyst change by adding code to the argument of the annotate() function? Select all that apply.
- Change the size of the text (Correct)
- Change the font style of the text (Correct)
- Change the color of the text (Correct)
- Change the text into a title for the plot
16. 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 years of data collection on your plot. Add a code chunk to the second line of code to map the aesthetic size to the variable year.
NOTE: the three dots (…) indicate where to add the code chunk. You may need to scroll in order to find the dots.
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, …))
What years does your visualization display?
- 2005-2009
- 2007-2009 (CORRECT)
- 2007-2011
- 2006-2010
Correct: Aesthetic size derives from year. This gives the actual scatter plot where the data points differ in size laterally per year.
17. Fill in the blank: The _____ creates a scatterplot and then adds a small amount of random noise to each point in the plot to make the points easier to find.
- geom_jitter() function (CORRECT)
- geom_smooth() function
- geom_point() function
- geom_bar() function
18. What function can be used to facet a plot on two variables?
- geom_wrap()
- facet_grid() (CORRECT)
- facet_layout()
- facet_wrap()
19. What argument of the labs() function can a data analyst use to add text outside of the grid area of a plot?
- text
- annotate
- title (CORRECT)
- note
20. In R studio, what default options does the Export functionality of the Plots tab give for exporting plots?
- HTML
- Slideshow
- Image (CORRECT)
- PDF (CORRECT)
21. You are working with the penguins dataset. You create a scatterplot with the following code chunk:
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
You want to highlight the different penguin species in your plot. Add a code chunk to the second line of code to map the aesthetic size to the variable bill_depth_mm.
NOTE: the three dots (…) indicate where to add the code chunk. You may need to scroll in order to find the dots.
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, …))
Which approximate range of bill depths does your visualization display?
- 20 – 31
- 14 – 20 (CORRECT)
- 31 – 40
- 2 – 9
22. What function can be used to facet a plot on two variables?
- geom_wrap()
- facet_grid() (CORRECT)
- facet_layout()
- facet_wrap()
23. Which of the following is a functionality of ggplot2?
- Combine data manipulation and visualizations using pipes. (CORRECT)
- Filter and sort data in complex ways.
- Define complex visualization using a single function.
- Create plots using artificial intelligence.
24. A data analyst creates a scatterplot. The analyst wants to put a text label on the plot to call out specific data points. What function does the analyst use?
- The annotate() function (CORRECT)
- The geom_smooth() function
- The facet_grid() function
- The ggplot() function
25. You are working with the penguins dataset. You create a scatterplot with the following code chunk:
ggplot(data = penguins) +
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
You want to highlight the different penguin species in 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. You may need to scroll in order to find the dots.
geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, …))
Which species tends to have the longest flipper length and highest body mass?
- Chinstrap
- Adelie
- Gentoo (CORRECT)
- Macaroni
26. What is the purpose of the facet_wrap() function?
- Create text inside a plot area
- Create subplots of a single variable into separate categories (CORRECT)
- Modify the visual characteristic of a data point
- Modify ggplot visuals to be three-dimensional
27. Which statement about the ggsave() function is correct?
- ggsave() is the only way to export a plot.
- ggsave() exports the last plot displayed by default. (CORRECT)
- ggsave() is run from the Plots Tab in RStudio.
- ggsave() is unable to save .png files.
28. A data analyst creates a scatterplot where the points are very crowded, which makes it hard to notice when points are stacked. What change can they make to their scatter plot to make it easier to notice the stacked data points?
- Change geom_point() to geom_jitter()(CORRECT)
- Change the shape of the points
- Change ggplot() to ggplot2()
- Change the color of the points
29. A data analyst wants to add a large piece of text above the grid area that clearly defines the purpose of a plot. Which ggplot function can they use to achieve this?
- annotate()
- labs() (CORRECT)
- subtitle()
- title()
30. 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.
ggplot(data = diamonds) + geom_bar(mapping = aes(x = color, fill = cut)) + facet_wrap(~clarity)
how many subplots does your visualization show?
- 8
- 9
- 6
- 7 (CORRECT)
More About Visualization, Aesthetics, and Annotations CONCLUSION
In this segment, you include a detailed overview of creating visualizations using R. You should then explore further how RStudio could help wing the aesthetics of visualization making it easier and more insightful.
Such a skill is handy when building annotated visualizations because it gives clear visibility and saves it for sharing or reuse. Want to keep building more around your learning on R as a tool for data visualization? Start looking at the Coursera experience of learning to get deeper on this topic!