B. geom_bar should use stat="count" instead of "identity".
C. aes() should not be used inside ggplot().
D. The fill color should be in quotes: fill="blue".
Solution
Step 1: Check fill color syntax
Colors in ggplot2 must be strings, so fill=blue is incorrect; it should be fill="blue".
Step 2: Verify other parts
stat="identity" is correct for bar heights from data; labs() can add titles; aes() is correctly used.
Final Answer:
The fill color should be in quotes: fill="blue". -> Option D
Quick Check:
Color names need quotes in ggplot2 [OK]
Hint: Put color names in quotes in ggplot2 [OK]
Common Mistakes:
Forgetting quotes around color names
Misunderstanding stat argument for geom_bar
Thinking labs() can't add titles
5. You want to create a customized scatter plot in R that highlights points with values above 50 in blue and others in gray. Which code snippet correctly achieves this using base R?
hard
A. plot(x, y, color = ifelse(y > 50, "blue", "gray"), pch = 16)
B. plot(x, y, col = ifelse(y > 50, "blue", "gray"), pch = 16)
C. plot(x, y, col = c("blue", "gray"), pch = 16)
D. plot(x, y, col = y > 50 ? "blue" : "gray", pch = 16)
Solution
Step 1: Understand color assignment in base R plots
The 'col' argument accepts a vector of colors matching points. Using ifelse(y > 50, "blue", "gray") creates this vector correctly.
Step 2: Check syntax correctness
plot(x, y, col = ifelse(y > 50, "blue", "gray"), pch = 16) uses correct R syntax with ifelse. plot(x, y, color = ifelse(y > 50, "blue", "gray"), pch = 16) uses 'color' which is invalid. plot(x, y, col = c("blue", "gray"), pch = 16) assigns only two colors without condition. plot(x, y, col = y > 50 ? "blue" : "gray", pch = 16) uses wrong ternary syntax (not valid in R).
Final Answer:
plot(x, y, col = ifelse(y > 50, "blue", "gray"), pch = 16) -> Option B
Quick Check:
Use ifelse for conditional colors in base R plots [OK]
Hint: Use ifelse() for conditional colors in base R plots [OK]
Common Mistakes:
Using 'color' instead of 'col'
Trying ternary operator syntax from other languages
Assigning color vector without matching points
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.