Visualization Quiz - Languages R
Free practice quiz: Visualization (Languages R). 49 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 49 questions freeSample questions
Which R package is most commonly used for creating static and interactive visualizations?
- lattice
- graphics
- ggplot2
- base
Show answer
Answer: C. ggplot2
ggplot2 is a powerful and widely adopted R package for data visualization, built on the Grammar of Graphics. It excels at creating both static and interactive plots with a flexible and expressive syntax.
In `ggplot2`, what does `scale_color_gradient()` typically do?
- Applies a discrete color palette
- Applies a continuous color gradient
- Maps colors to categorical variables
- Sets the transparency of the plot elements
Show answer
Answer: B. Applies a continuous color gradient
`scale_color_gradient()` is used to define a continuous color scale, mapping a continuous variable to a gradient of colors, often useful for heatmaps or choropleth maps.
Which aesthetic is typically used to map a categorical variable to different colors in a `ggplot2` plot?
- `size`
- `alpha`
- `color`
- `shape`
Show answer
Answer: C. `color`
The `color` aesthetic in `ggplot2` is used to distinguish elements by color. When mapped to a categorical variable, it assigns a different color to each category.
Which of the following is a valid way to specify the grouping variable for `geom_bar()` to create stacked or dodged bars?
- `aes(x = category, y = count, fill = group_variable)`
- `aes(x = category, y = count, color = group_variable)`
- `aes(x = category, y = count, alpha = group_variable)`
- All of the above
Show answer
Answer: A. `aes(x = category, y = count, fill = group_variable)`
Mapping a grouping variable to the `fill` aesthetic within `geom_bar()` tells `ggplot2` how to stack or dodge the bars based on that grouping variable. While `color` can also be used for outlines, `fill` is standard for segmenting bars.
When mapping a numerical variable to `size` in `ggplot2`, what type of scale would typically be used?
- `scale_size_manual()`
- `scale_size_continuous()`
- `scale_size_discrete()`
- `scale_size_gradient()`
Show answer
Answer: B. `scale_size_continuous()`
For numerical variables mapped to `size`, `scale_size_continuous()` is used to create a gradient of sizes corresponding to the range of numerical values. `scale_size_gradient()` is a specific type of continuous scale. `scale_size_discrete()` is for categorical variables.