MCQs on Intermediate Data Visualization | R

Mastering intermediate data visualization in R with ggplot2 is essential for creating compelling visualizations. This chapter covers topics like customizing aesthetics, themes, layouts, and building advanced plots, such as facets and maps.


Chapter: Intermediate Data Visualization in R – MCQs

1. Introduction to ggplot2

  1. What is ggplot2 used for in R?
    • a) Statistical analysis
    • b) Machine learning
    • c) Data visualization
    • d) Data cleaning
  2. Which function is used to create a basic plot in ggplot2?
    • a) plot()
    • b) ggplot()
    • c) geom_plot()
    • d) ggcreate()
  3. Which package must be installed in R to use ggplot2?
    • a) ggplot2
    • b) tidyverse
    • c) ggthemes
    • d) data.table
  4. What is the function used to add layers to a plot in ggplot2?
    • a) add_layer()
    • b) plot_layer()
    • c) geom_*()
    • d) layer()
  5. Which of the following is a valid aesthetic mapping in ggplot2?
    • a) color
    • b) plot
    • c) axis
    • d) graph
  6. Which of the following is used to specify the data source for a ggplot?
    • a) aes()
    • b) ggplot()
    • c) data.frame()
    • d) geom()
  7. What does the aes() function do in ggplot2?
    • a) Defines the dataset
    • b) Specifies aesthetic mappings
    • c) Creates a plot
    • d) Sets the title of a plot
  8. What type of plot is created by geom_point() in ggplot2?
    • a) Line plot
    • b) Bar chart
    • c) Scatter plot
    • d) Histogram
  9. How do you specify the color of points in a scatter plot in ggplot2?
    • a) color aesthetic
    • b) fill aesthetic
    • c) border aesthetic
    • d) size aesthetic
  10. Which function is used to add a line of best fit to a plot in ggplot2?
    • a) geom_line()
    • b) geom_smooth()
    • c) geom_histogram()
    • d) geom_boxplot()

2. Customizing Aesthetics, Themes, and Layouts

  1. Which function is used to change the color of the background of a ggplot?
    • a) theme()
    • b) theme_bw()
    • c) set_theme()
    • d) set_bg_color()
  2. How can you change the x-axis label in a ggplot2 plot?
    • a) xlab()
    • b) axis_label()
    • c) set_xlabel()
    • d) label_x()
  3. Which function can be used to apply a predefined theme to a ggplot2 plot?
    • a) theme_set()
    • b) ggtheme()
    • c) theme_*()
    • d) set_theme()
  4. What does the labs() function do in ggplot2?
    • a) Sets the color of plot elements
    • b) Adds titles and labels to a plot
    • c) Defines the layout of the plot
    • d) Adds data to the plot
  5. How can you change the size of axis labels in ggplot2?
    • a) Using the theme() function and axis.title.size parameter
    • b) Using the axis_size() function
    • c) By modifying the ggplot() function directly
    • d) Using the labs() function
  6. Which of the following is used to customize the color of lines in ggplot2?
    • a) color aesthetic
    • b) line_color() function
    • c) line_aesthetic()
    • d) plot_color()
  7. How can you remove the legend in ggplot2?
    • a) theme(legend.position = "none")
    • b) remove_legend()
    • c) no_legend()
    • d) legend(FALSE)
  8. What is the function to adjust the plot margin in ggplot2?
    • a) theme()
    • b) margin()
    • c) adjust_margin()
    • d) plot_margin()
  9. How can you customize the tick marks on the axes in ggplot2?
    • a) Using scale_x_continuous() or scale_y_continuous()
    • b) By modifying the theme() function
    • c) Using axis_ticks()
    • d) With set_ticks()
  10. Which function is used to modify the plot gridlines in ggplot2?
    • a) theme()
    • b) grid_lines()
    • c) grid_custom()
    • d) set_grid()

3. Creating Advanced Plots (Facets, Maps, etc.)

  1. What is the purpose of facetting in ggplot2?
    • a) To group data into subplots based on a variable
    • b) To add a legend to a plot
    • c) To adjust the axis labels
    • d) To modify the colors of plot elements
  2. Which function is used to create faceted plots in ggplot2?
    • a) facet_wrap()
    • b) facet_grid()
    • c) facet()
    • d) facet_plot()
  3. What does the facet_wrap() function do in ggplot2?
    • a) Creates a grid of subplots based on a categorical variable
    • b) Creates a series of plots using different continuous variables
    • c) Adds a title to the plot
    • d) Creates a histogram
  4. How do you create a map plot in ggplot2?
    • a) By using geom_map() and a map dataset
    • b) By using geom_polygon()
    • c) By using geom_path()
    • d) By using geom_area()
  5. Which of the following is used to create a heatmap in ggplot2?
    • a) geom_tile()
    • b) geom_bar()
    • c) geom_boxplot()
    • d) geom_point()
  6. How can you adjust the scale of a continuous variable in ggplot2?
    • a) Using scale_*_continuous()
    • b) By modifying the geom_*() function
    • c) Using set_scale()
    • d) By using continuous_scale()
  7. Which function is used to plot geographic data in ggplot2?
    • a) geom_sf()
    • b) geom_map()
    • c) geom_map_data()
    • d) geom_location()
  8. How do you control the legend position in ggplot2?
    • a) By using the theme(legend.position = ) argument
    • b) With the set_legend() function
    • c) By modifying the labs() function
    • d) By using legend_location()
  9. How can you add a title to a ggplot in R?
    • a) Using ggtitle()
    • b) By modifying the theme() function
    • c) Using labs()
    • d) Using title()
  10. How do you adjust the transparency of plot elements in ggplot2?
    • a) Using the alpha aesthetic
    • b) Using transparency()
    • c) Using geom_transparent()
    • d) Using the opacity function

Answers Table

QnoAnswer
1c) Data visualization
2b) ggplot()
3a) ggplot2
4c) geom_*()
5a) color
6b) ggplot()
7b) Specifies aesthetic mappings
8c) Scatter plot
9a) color aesthetic
10b) geom_smooth()
11a) theme()
12a) xlab()
13c) theme_*()
14b) Adds titles and labels to a plot
15a) Using the theme() function and axis.title.size parameter
16a) color aesthetic
17a) theme(legend.position = "none")
18a) theme()
19a) Using scale_x_continuous() or scale_y_continuous()
20a) theme()
21a) To group data into subplots based on a variable
22a) facet_wrap()
23a) Creates a grid of subplots based on a categorical variable
24a) By using geom_map() and a map dataset
25a) geom_tile()
26a) Using scale_*_continuous()
27a) geom_sf()
28a) By using the theme(legend.position = ) argument
29a) Using ggtitle()
30a) Using the alpha aesthetic

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top