R Programming Language Certification Data Visualization & Reporting 1 — Questions and Answers
Question 1: Which R package is most widely used for creating layered, publication-quality graphics?
- lattice
- base graphics
- ggplot2 (Correct answer)
- plotly
Correct answer: ggplot2
ggplot2 implements the Grammar of Graphics, allowing users to build complex, publication-quality plots by layering geometric objects and aesthetics.
Question 2: In ggplot2, which function adds a scatter plot layer to a plot?
- geom_line()
- geom_bar()
- geom_point() (Correct answer)
- geom_histogram()
Correct answer: geom_point()
geom_point() adds a layer of points to a ggplot2 chart, creating a scatter plot when mapped to x and y aesthetics.
Question 3: What does the aes() function define in ggplot2?
- Plot colors and fonts
- Aesthetic mappings between data variables and visual properties (Correct answer)
- Axis labels and titles
- Theme settings
Correct answer: Aesthetic mappings between data variables and visual properties
aes() (aesthetics) maps data variables to visual properties like x/y position, color, size, and shape in a ggplot2 plot.
Question 4: Which ggplot2 function creates separate panels for subsets of data?
- facet_wrap() (Correct answer)
- split_plot()
- panel_grid()
- group_plot()
Correct answer: facet_wrap()
facet_wrap() creates a multi-panel plot by wrapping panels for each level of a categorical variable into a rectangular layout.
Question 5: In R Markdown, which chunk option prevents code from being displayed in the output?
- echo=TRUE
- eval=FALSE
- echo=FALSE (Correct answer)
- include=FALSE
Correct answer: echo=FALSE
echo=FALSE hides the code chunk from the rendered output while still executing it and showing any results or plots it produces.
Question 6: Which function saves a ggplot2 plot to a file?
- save_plot()
- export_plot()
- ggsave() (Correct answer)
- write_plot()
Correct answer: ggsave()
ggsave() saves the last displayed ggplot2 plot (or a specified plot object) to a file, inferring format from the file extension.
Which R package is most widely used for creating layered, publication-quality graphics?