0
0
R Programmingprogramming~10 mins

Color scales and palettes in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic color palette with three colors.

R Programming
palette <- c("red", [1], "blue")
print(palette)
Drag options to blanks, or click blank then click option'
A"orange"
B"green"
C"purple"
D"yellow"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color name without quotes
Forgetting commas between colors
2fill in blank
medium

Complete the code to generate a color gradient from blue to red with 5 colors using colorRampPalette.

R Programming
colors <- colorRampPalette(c("blue", [1]))(5)
print(colors)
Drag options to blanks, or click blank then click option'
A"purple"
B"yellow"
C"green"
D"red"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color not matching the gradient end
Missing quotes around color names
3fill in blank
hard

Fix the error in the code to correctly display a palette of 4 colors using brewer.pal from RColorBrewer.

R Programming
library(RColorBrewer)
palette <- brewer.pal([1], "Set1")
print(palette)
Drag options to blanks, or click blank then click option'
A4
B3
C5
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number less than 3
Using a number greater than the palette max
4fill in blank
hard

Fill both blanks to create a named vector of colors for categories using a manual palette.

R Programming
categories <- c("A", "B", "C")
colors <- c([1] = "red", [2] = "blue", "green")
names(colors) <- categories
print(colors)
Drag options to blanks, or click blank then click option'
A"cat1"
B"catA"
C"catB"
D"catC"
Attempts:
3 left
💡 Hint
Common Mistakes
Using names that are not strings
Repeating the same name twice
5fill in blank
hard

Fill all three blanks to create a color scale using ggplot2 with a manual palette for factor levels.

R Programming
library(ggplot2)
data <- data.frame(x = 1:3, y = c(3, 2, 5), group = factor(c("low", "medium", "high")))
ggplot(data, aes(x, y, color = group)) +
  geom_point(size = 5) +
  scale_color_manual(values = c([1] = "blue", [2] = "orange", [3] = "green"))
Drag options to blanks, or click blank then click option'
A"low"
B"medium"
C"high"
D"group"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of factor levels
Missing quotes around names