R Programming Language Certification Data Visualization & Graphics in R 1 — Questions and Answers
Question 1: Which R package is most widely used for creating advanced data visualizations based on the Grammar of Graphics?
- ggplot2 (Correct answer)
- lattice
- base graphics
- plotly
Correct answer: ggplot2
ggplot2, created by Hadley Wickham, implements the Grammar of Graphics and is the most popular R visualization package.
Question 2: In ggplot2, which function is used to add a scatter plot layer to a plot?
- geom_point() (Correct answer)
- geom_scatter()
- geom_dot()
- geom_xy()
Correct answer: geom_point()
geom_point() adds a layer of points to a ggplot2 visualization, creating a scatter plot.
Question 3: What does the aes() function do in ggplot2?
- Defines aesthetic mappings between data variables and visual properties (Correct answer)
- Sets color themes
- Adjusts axis scales
- Exports plots to files
Correct answer: Defines aesthetic mappings between data variables and visual properties
aes() (aesthetic mappings) maps data variables to visual properties like x, y, color, size, and shape.
Question 4: Which ggplot2 function is used to create separate panels for different subsets of data?
- facet_wrap() (Correct answer)
- panel_split()
- grid_layout()
- subset_plot()
Correct answer: facet_wrap()
facet_wrap() creates a matrix of panels, each showing a different subset of the data defined by a categorical variable.
Question 5: In base R, which function saves a plot as a PNG file?
- png() (Correct answer)
- save_plot()
- export_png()
- write_plot()
Correct answer: png()
png() opens a PNG graphics device; after drawing the plot, dev.off() closes and saves the file.
Question 6: Which ggplot2 function changes the overall visual style of a plot (background, grid lines, font)?
- theme() (Correct answer)
- style()
- format()
- layout()
Correct answer: theme()
theme() controls non-data elements of a ggplot2 plot, including background, grid lines, axis text, and legend formatting.
Which R package is most widely used for creating advanced data visualizations based on the Grammar of Graphics?