A. The argument 'labels' should be 'legend' in the legend() function
B. The position 'top' is invalid in legend()
C. The colors 1:5 are not valid color codes
D. pch = 15 is not a valid plotting character
Solution
Step 1: Check legend() argument names
The correct argument for labels is 'legend', not 'labels'. Using 'labels' causes no legend to appear.
Step 2: Verify position and other parameters
Position 'top' is valid, colors 1:5 are valid R colors, pch=15 is a valid filled square symbol.
Final Answer:
The argument 'labels' should be 'legend' in the legend() function -> Option A
Quick Check:
Use legend=, not labels= in legend() [OK]
Hint: Use legend= for labels inside legend() [OK]
Common Mistakes:
Using 'labels' instead of 'legend' argument
Thinking 'top' is invalid position
Confusing color codes with integers
5. You want to create a plot with two groups of points: group A in red circles and group B in blue triangles. How do you add a legend that clearly shows these groups with correct symbols and colors?
hard
A. legend("topright", legend = c("Group A", "Group B"), col = c(1, 2), pch = c(16, 17))