R Programming Language Certification Data Visualization & Reporting 2 — Questions and Answers
Question 1: Which ggplot2 function modifies the overall appearance of a plot (background, gridlines, fonts)?
- theme() (Correct answer)
- scale_color_manual()
- labs()
- coord_flip()
Correct answer: theme()
theme() controls non-data visual elements like background color, gridlines, axis text, legend position, and title fonts.
Question 2: What does coord_flip() do in ggplot2?
- Reverses the color scale
- Swaps the x and y axes (Correct answer)
- Flips the plot to polar coordinates
- Inverts the y-axis direction
Correct answer: Swaps the x and y axes
coord_flip() swaps the x and y axes, which is commonly used to turn vertical bar charts into horizontal bar charts for better label readability.
Question 3: Which R Markdown output format produces an HTML document?
- pdf_document
- word_document
- html_document (Correct answer)
- beamer_presentation
Correct answer: html_document
html_document in the YAML front matter of an R Markdown file renders the document as a self-contained HTML file viewable in a browser.
Question 4: Which function adds axis labels and a title to a ggplot2 plot?
- title()
- axis_labels()
- labs() (Correct answer)
- annotate()
Correct answer: labs()
labs() sets plot labels including title, subtitle, caption, and axis labels (x, y) in a single concise function call.
Question 5: Which ggplot2 geom creates a box plot?
- geom_box()
- geom_boxplot() (Correct answer)
- geom_whisker()
- geom_quartile()
Correct answer: geom_boxplot()
geom_boxplot() draws box plots showing the median, quartiles, and outliers for a continuous variable, optionally grouped by a categorical variable.
Question 6: In the Shiny framework in R, which function creates a user interface layout with a sidebar and main panel?
- fluidPage()
- sidebarLayout() (Correct answer)
- bootstrapPage()
- navbarPage()
Correct answer: sidebarLayout()
sidebarLayout() creates a two-column layout with a sidebar panel (for inputs) and a main panel (for outputs) in a Shiny application.
Which ggplot2 function modifies the overall appearance of a plot (background, gridlines, fonts)?