Week 12 · Advanced Statistical Programming using R
Where should the units of a numeric column (e.g. mm, g) go in a well-designed table?
Answer: 3) Units belong in the column header, e.g. “Bill length (mm)”. This keeps cells scannable and reduces visual clutter.
What are the main roles of the subtitle and caption below a chart?
Answer: 2) The subtitle carries the message. The caption grounds the chart in its source, so readers can verify or cite it.
What is the fastest way to turn an existing ggplot2 plot into an interactive one?
ggplotly()install.packages("plotly") onlyAnswer: 2) ggplotly(p) converts a static ggplot2 object into an interactive plotly chart. Hover, zoom, and legend toggles work automatically.
Which package category works without needing a running R server?
plotly, leaflet, DTserver in the nameAnswer: 1) htmlwidgets embed pre-rendered JavaScript into HTML. They work in any Quarto or R Markdown HTML output and static sites like GitHub Pages.
Which interactive features does plotly add to a plot? (multiple correct answers)
Answer: 1, 2 & 4)
Correct: 1. Hover tooltips reveal values on mouse-over.
Correct: 2. Legend clicks toggle groups on and off.
Correct: 4. Box-select and zoom highlight regions of interest.
False: 3. plotly renders plots, it does not fit models.
You want to add a marker at a specific latitude and longitude on an interactive map. Which pipeline works?
ggplot() + geom_point()plot() + points()map_data("world") + geom_polygon()leaflet() |> addTiles() |> addMarkers(lng, lat, popup)Answer: 4) leaflet() starts the map, addTiles() supplies the OpenStreetMap background, addMarkers() places pins with popups.
What is an sf object in R?
geometry columnAnswer: 3) sf (Simple Features) objects behave like normal data frames. The geometry column stores the shape, and you can pipe through dplyr as usual.
What does geom_sf() do in a ggplot2 call?
sf object with automatic projection handlingsf formatAnswer: 2) geom_sf() plots the geometry column and manages the map projection. Combine it with aes(fill = ...) for choropleths.
When would you prefer {geofacet} over a standard choropleth (geom_sf())?
ggplot2Answer: 4) {geofacet} arranges facet_wrap() panels in a geographic layout. Great for showing time series or distributions per region side by side.
Which R package lets you call Python code and share data between both languages in the same session?
dplyr::pythonpydiversereticulateRythonAnswer: 3) reticulate is R’s bridge to Python. It lets you import Python modules, run scripts, and pass data frames back and forth in one Quarto document.