Challenge - 5 Problems
Legend Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this legend control code?
Consider the following R code that creates a plot with a legend. What will be the color of the legend text?
R Programming
plot(1:5, col = c("red", "blue", "green", "purple", "orange"), pch = 19, cex = 2) legend("topright", legend = c("A", "B", "C", "D", "E"), col = c("red", "blue", "green", "purple", "orange"), pch = 19, text.col = "blue")
Attempts:
2 left
💡 Hint
Look at the 'text.col' parameter in the legend function.
✗ Incorrect
The 'text.col' argument in the legend function sets the color of the legend text. Here it is set to 'blue', so the legend text will appear blue.
❓ Predict Output
intermediate2:00remaining
What happens if you set 'bty = "n"' in legend()?
Given this R code snippet, what will be the effect on the legend box?
R Programming
plot(1:3, col = c("red", "green", "blue"), pch = 19, cex = 2) legend("topright", legend = c("Red", "Green", "Blue"), col = c("red", "green", "blue"), pch = 19, bty = "n")
Attempts:
2 left
💡 Hint
Check the meaning of the 'bty' parameter in legend().
✗ Incorrect
Setting 'bty = "n"' tells R not to draw the box around the legend, so the legend appears without a border.
❓ Predict Output
advanced2:00remaining
What is the output of this legend with multiple line labels?
What will be the appearance of the legend text in this R code?
R Programming
plot(1:4, col = c("red", "blue", "green", "purple"), pch = 19, cex = 2) legend("bottomleft", legend = c("First line\nSecond line", "Blue", "Green", "Purple"), col = c("red", "blue", "green", "purple"), pch = 19)
Attempts:
2 left
💡 Hint
Check how legend() handles newline characters in labels.
✗ Incorrect
The legend function does not interpret '\n' as a newline in labels; it shows the literal string '\n'.
❓ Predict Output
advanced2:00remaining
What is the effect of 'inset' parameter in legend()?
Given this R code, where will the legend appear relative to the plot area?
R Programming
plot(1:5, col = "black", pch = 19, cex = 2) legend("topright", legend = "Point", pch = 19, inset = 0.1)
Attempts:
2 left
💡 Hint
The 'inset' parameter moves the legend inside the plot margins by a fraction.
✗ Incorrect
The 'inset' parameter moves the legend inside the plot area by the given fraction of the plot region. 0.1 means 10%.
❓ Predict Output
expert2:00remaining
What is the output of this legend with 'fill' and 'border' parameters?
Analyze the following R code. What will be the color of the legend boxes and their borders?
R Programming
plot(1:3, pch = 22, cex = 3) legend("bottomright", legend = c("Red", "Green", "Blue"), fill = c("red", "green", "blue"), border = c("black", "yellow", "white"))
Attempts:
2 left
💡 Hint
Check how 'fill' and 'border' parameters work together in legend().
✗ Incorrect
The 'fill' parameter colors the boxes inside the legend, and 'border' sets the color of the box borders individually.