0
0
R Programmingprogramming~20 mins

Labels and titles in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label and Title Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this plot title code?
Consider the following R code that creates a simple plot with a title and axis labels. What will be the title of the plot when this code runs?
R Programming
plot(1:5, 1:5, main = "My Plot Title", xlab = "X Axis", ylab = "Y Axis")
title(main = "Overridden Title")
AOverridden Title
BX Axis
CY Axis
DMy Plot Title
Attempts:
2 left
💡 Hint
The title() function can override the main title set in plot().
Predict Output
intermediate
2:00remaining
What label appears on the x-axis?
What label will appear on the x-axis after running this R code?
R Programming
barplot(1:3, names.arg = c("A", "B", "C"), xlab = "Category")
AA, B, C
BCategory
C1, 2, 3
DNo label
Attempts:
2 left
💡 Hint
xlab sets the label for the x-axis, names.arg sets the names for bars.
🔧 Debug
advanced
2:00remaining
Why does this plot title not appear?
This R code is intended to add a title to the plot, but no title appears. What is the cause?
R Programming
plot(1:10, 1:10)
title(main = "My Title", sub = "Subtitle")
title(xlab = "X Label")
AThe xlab argument in title() does not set the x-axis label; it must be set in plot().
BThe title() function cannot add subtitles; sub is ignored.
CThe plot() function must include main argument to show any title.
DThe title() function calls overwrite each other, so only the last call works.
Attempts:
2 left
💡 Hint
Check which arguments title() accepts and which must be set in plot().
🧠 Conceptual
advanced
2:00remaining
How to add multiple lines in a plot title?
Which option correctly adds a multi-line main title to a plot in R?
Aplot(1:5, main = "Line 1\nLine 2")
Bplot(1:5, main = c("Line 1", "Line 2"))
Cplot(1:5); title(main = "Line 1\nLine 2")
Dplot(1:5); title(main = c("Line 1", "Line 2"))
Attempts:
2 left
💡 Hint
Use newline characters in strings or multiple calls to title().
Predict Output
expert
3:00remaining
What is the output of this label and title code?
What will be the main title and axis labels of the plot after running this R code?
R Programming
plot(1:3, 1:3, main = "First Title", xlab = "X1", ylab = "Y1")
title(main = "Second Title", xlab = "X2")
title(ylab = "Y2")
AMain title: Second Title; X-axis label: X1; Y-axis label: Y1
BMain title: First Title; X-axis label: X1; Y-axis label: Y1
CMain title: First Title; X-axis label: X2; Y-axis label: Y2
DMain title: Second Title; X-axis label: X2; Y-axis label: Y2
Attempts:
2 left
💡 Hint
title() can override main and sub titles but not axis labels; check which labels are updated.