0
0
R Programmingprogramming~20 mins

Color scales and palettes in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Color Scale Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a basic colorRampPalette function
What is the output of this R code snippet?
R Programming
pal <- colorRampPalette(c("red", "blue"))
colors <- pal(3)
print(colors)
A[1] "#FF0000" "#400080" "#0000FF"
B[1] "red" "purple" "blue"
C[1] "#FF0000" "#FF00FF" "#0000FF"
D[1] "#FF0000" "#800080" "#0000FF"
Attempts:
2 left
💡 Hint
colorRampPalette creates a gradient of colors between the given colors.
🧠 Conceptual
intermediate
2:00remaining
Understanding colorRamp vs colorRampPalette
Which statement correctly describes the difference between colorRamp and colorRampPalette in R?
AcolorRampPalette interpolates colors as numeric RGB values; colorRamp returns hex color strings.
BcolorRamp generates a vector of colors; colorRampPalette returns RGB values only.
CcolorRamp returns a function that interpolates colors as RGB values; colorRampPalette returns a function that generates a vector of colors as hex strings.
DBoth functions return the same output but differ in input format.
Attempts:
2 left
💡 Hint
Think about what type of output each function produces.
Predict Output
advanced
2:00remaining
Output of a custom palette with transparency
What is the output of this R code?
R Programming
pal <- colorRampPalette(c("#FF000080", "#0000FF80"), alpha = TRUE)
colors <- pal(2)
print(colors)
A[1] "#FF0000FF" "#0000FFFF"
B[1] "#FF000080" "#0000FF80"
C[1] "#FF0000" "#0000FF"
D[1] "#FF0080" "#000080"
Attempts:
2 left
💡 Hint
Check how colorRampPalette handles alpha transparency in hex colors.
Predict Output
advanced
2:00remaining
Number of colors generated by brewer.pal
What is the length of the vector returned by brewer.pal(5, "Set1") in R?
R Programming
library(RColorBrewer)
colors <- brewer.pal(5, "Set1")
length(colors)
A5
B8
C3
D7
Attempts:
2 left
💡 Hint
brewer.pal returns the number of colors requested up to the palette maximum.
🔧 Debug
expert
2:00remaining
Identify the error in this colorRampPalette usage
What error does this R code produce?
R Programming
pal <- colorRampPalette(c(123, 456))
colors <- pal(3)
print(colors)
AError in colorRampPalette: 'colors' must be character vector
BError in pal(3): invalid number of colors requested
CNo error; outputs three colors
DError in print: object 'colors' not found
Attempts:
2 left
💡 Hint
Check the input types for colorRampPalette.