What function in R is used to add a main title to a plot?
The title() function is used to add a main title to a plot in R.
Click to reveal answer
beginner
How do you add labels to the x-axis and y-axis in an R plot?
You can add labels to the x-axis and y-axis using the xlab and ylab arguments inside the plot() function or by using the title() function with xlab and ylab arguments.
Click to reveal answer
beginner
What argument inside the plot() function controls the main title?
The main argument inside plot() controls the main title of the plot.
Click to reveal answer
intermediate
How can you add a subtitle to a plot in R?
You can add a subtitle using the sub argument inside the plot() function or by calling title(sub = "Your subtitle") after the plot.
Click to reveal answer
beginner
What is the difference between main and sub in R plotting?
main sets the main title at the top of the plot, while sub sets a subtitle below the plot.
Click to reveal answer
Which argument adds a main title directly inside the plot() function?
Amain
Btitle
Clabel
Dcaption
✗ Incorrect
The main argument inside plot() adds the main title.
How do you add a label to the x-axis in a plot?
AUse <code>xlab</code> argument
BUse <code>ylab</code> argument
CUse <code>main</code> argument
DUse <code>sub</code> argument
✗ Incorrect
xlab sets the label for the x-axis.
Which function can add a title after a plot is created?
Alabel()
Bplot()
Ctitle()
Daxis()
✗ Incorrect
title() adds or modifies titles after the plot is drawn.
What does the sub argument do in R plotting?
AAdds a main title
BAdds a subtitle below the plot
CLabels the y-axis
DLabels the x-axis
✗ Incorrect
sub adds a subtitle below the plot.
If you want to label the y-axis, which argument do you use?
Asub
Bxlab
Cmain
Dylab
✗ Incorrect
ylab sets the label for the y-axis.
Explain how to add a main title, x-axis label, and y-axis label to a plot in R.
Think about the arguments inside the plot() function.
You got /4 concepts.
Describe the difference between the 'main' and 'sub' arguments in R plotting.
Consider where the text appears on the plot.
You got /3 concepts.
Practice
(1/5)
1. What is the purpose of using main in an R plot?
easy
A. To add a main title to the plot
B. To label the x-axis
C. To label the y-axis
D. To change the plot color
Solution
Step 1: Understand the role of main in plotting
The main argument in R's plot function is used to set the main title of the graph.
Step 2: Differentiate from axis labels
xlab and ylab are used for x-axis and y-axis labels respectively, not main.
2. Which of the following is the correct syntax to add a y-axis label "Height" in an R plot?
easy
A. plot(x, y, xlab = "Height")
B. plot(x, y, ylab = "Height")
C. plot(x, y, main = "Height")
D. plot(x, y, label = "Height")
Solution
Step 1: Identify the argument for y-axis label
In R, ylab is used to set the label for the y-axis.
Step 2: Check the syntax correctness
The syntax plot(x, y, ylab = "Height") correctly assigns "Height" as the y-axis label.
Final Answer:
plot(x, y, ylab = "Height") -> Option B
Quick Check:
ylab = y-axis label [OK]
Hint: Use ylab for y-axis label inside plot() [OK]
Common Mistakes:
Using main instead of ylab for y-axis label
Using xlab for y-axis label
Using a non-existent label argument
3. What will be the main title of the plot after running this code?
plot(1:5, 1:5, main = "Sales Over Time", xlab = "Month", ylab = "Sales")
medium
A. Month
B. No title
C. Sales
D. Sales Over Time
Solution
Step 1: Identify the main title argument
The argument main = "Sales Over Time" sets the main title of the plot.
Step 2: Confirm other labels are axis labels
xlab = "Month" and ylab = "Sales" set the x-axis and y-axis labels, not the main title.
Final Answer:
Sales Over Time -> Option D
Quick Check:
main = "Sales Over Time" [OK]
Hint: main sets the plot title, not axis labels [OK]
Common Mistakes:
Confusing xlab or ylab as main title
Ignoring the main argument
Assuming no title if not obvious
4. Identify the error in this R plot code:
plot(x, y, main = "Data", xlabel = "Time", ylab = "Value")
medium
A. The argument 'xlabel' is incorrect; it should be 'xlab'
B. The argument 'main' should be 'title'
C. The argument 'ylab' should be 'ylabel'
D. There is no error in the code
Solution
Step 1: Check the axis label arguments
In R, the correct argument for x-axis label is xlab, not xlabel.
Step 2: Verify other arguments
main is correct for the title, and ylab is correct for y-axis label.
Final Answer:
The argument 'xlabel' is incorrect; it should be 'xlab' -> Option A
Quick Check:
Use xlab, not xlabel [OK]
Hint: Use xlab and ylab, not xlabel or ylabel [OK]
Common Mistakes:
Using xlabel instead of xlab
Using ylabel instead of ylab
Changing main to title incorrectly
5. You want to create a plot with the main title "Temperature Trends", x-axis label "Year", and y-axis label "Temperature (°C)". Which code correctly achieves this?
hard
A. plot(years, temps, main = "Temperature Trends", xlab = "Year")
B. plot(years, temps, title = "Temperature Trends", xlabel = "Year", ylabel = "Temperature (°C)")
C. plot(years, temps, main = "Temperature Trends", xlab = "Year", ylab = "Temperature (°C)")
D. plot(years, temps, main = "Temperature Trends", xlabel = "Year", ylab = "Temperature (°C)")
Solution
Step 1: Use correct arguments for labels and title
The correct arguments are main for the title, xlab for the x-axis label, and ylab for the y-axis label.