11
What is the purpose of the labs() function in ggplot2?
A)
Customizes the labels and captions of the plot
B)
Adds a legend to the plot
C)
Sets the size of the plot margins
D)
Applies statistical transformations to the data
Answer & Solution
Answer: Option
A
12
How do you create a histogram in ggplot2 for a numeric variable named variable?
A)
geom_histogram(x = variable)
B)
histogram(variable)
C)
geom_hist(mapping = aes(x = variable))
D)
hist_plot(variable)
Answer & Solution
Answer: Option
C
13
In ggplot2, how do you add a smooth line to a scatter plot?
A)
geom_smooth()
B)
smooth_line()
C)
geom_line_smooth()
D)
line_smooth()
Answer & Solution
Answer: Option
A
14
How do you customize the color of data points based on a categorical variable color_var in a ggplot2 scatter plot?
A)
scale_color_manual(values = color_var)
B)
scale_color_identity()
C)
color = color_var
D)
aes(color = color_var)
Answer & Solution
Answer: Option
A
15
In ggplot2, how do you customize the x-axis labels for a categorical variable category?
A)
scale_x_continuous(labels = category)
B)
theme(axis.text.x = element_text(labels = category))
C)
labs(x = category)
D)
scale_x_discrete(labels = category)
Answer & Solution
Answer: Option
D
16
In ggplot2, how do you add a color gradient to a scatter plot based on a numeric variable color_var?
A)
scale_fill_gradient(low = "blue", high = "red")
B)
color_gradient(low = "blue", high = "red")
C)
scale_color_gradient(low = "blue", high = "red")
D)
geom_point(aes(color = color_var), fill = "blue")
Answer & Solution
Answer: Option
C
17
What is the purpose of the geom_bar(stat = "identity") syntax in ggplot2?
A)
Plots the counts directly without statistical transformation
B)
Adds statistical transformation to the bar plot
C)
Identifies the identity of each bar in the plot
D)
Maps the identity of each data point to the y-axis
Answer & Solution
Answer: Option
A
18
How do you create a violin plot in ggplot2 for a numerical variable named values grouped by a factor variable group?
A)
geom_violin(x = group, y = values)
B)
geom_violin(mapping = aes(x = group, y = values))
C)
violin_plot(group, values)
D)
geom_violin(aes(x = group, y = values))
Answer & Solution
Answer: Option
D
19
In ggplot2, what is the role of the coord_polar() function?
A)
Converts a scatter plot to a polar coordinate system
B)
Adds polar coordinates to the plot
C)
Modifies the polar coordinates of a specific layer
D)
Coordinates the position of labels in a polar plot
Answer & Solution
Answer: Option
A
20
How do you create a stacked bar plot in ggplot2 for two categorical variables category1 and category2?
A)
geom_bar(aes(x = category1, fill = category2), position = "stack")
B)
stacked_bar(category1, category2)
C)
geom_bar(mapping = aes(x = category1, fill = category2), stat = "stack")
D)
bar_plot_stack(category1, category2)
Answer & Solution
Answer: Option
A