Any2Quiz
Computer Science / Languages / R

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 free

Sample questions

  1. Which R package is most commonly used for creating static and interactive visualizations?

    1. lattice
    2. graphics
    3. ggplot2
    4. 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.

  2. In `ggplot2`, what does `scale_color_gradient()` typically do?

    1. Applies a discrete color palette
    2. Applies a continuous color gradient
    3. Maps colors to categorical variables
    4. 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.

  3. Which aesthetic is typically used to map a categorical variable to different colors in a `ggplot2` plot?

    1. `size`
    2. `alpha`
    3. `color`
    4. `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.

  4. Which of the following is a valid way to specify the grouping variable for `geom_bar()` to create stacked or dodged bars?

    1. `aes(x = category, y = count, fill = group_variable)`
    2. `aes(x = category, y = count, color = group_variable)`
    3. `aes(x = category, y = count, alpha = group_variable)`
    4. 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.

  5. When mapping a numerical variable to `size` in `ggplot2`, what type of scale would typically be used?

    1. `scale_size_manual()`
    2. `scale_size_continuous()`
    3. `scale_size_discrete()`
    4. `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.

Take the full quiz

More quizzes

Browse all R quizzes