Complete the code to create a basic color palette with three colors.
palette <- c("red", [1], "blue") print(palette)
The code creates a vector of colors. "green" is the correct middle color to complete the palette.
Complete the code to generate a color gradient from blue to red with 5 colors using colorRampPalette.
colors <- colorRampPalette(c("blue", [1]))(5) print(colors)
The function colorRampPalette creates a gradient between the colors given. "red" is needed to create a gradient from blue to red.
Fix the error in the code to correctly display a palette of 4 colors using brewer.pal from RColorBrewer.
library(RColorBrewer) palette <- brewer.pal([1], "Set1") print(palette)
brewer.pal requires the number of colors to be between 3 and the maximum allowed for the palette. "Set1" supports up to 9 colors, so 4 is correct.
Fill both blanks to create a named vector of colors for categories using a manual palette.
categories <- c("A", "B", "C") colors <- c([1] = "red", [2] = "blue", "green") names(colors) <- categories print(colors)
The named vector assigns names to colors. "catA" and "catB" are used as names for the first two colors.
Fill all three blanks to create a color scale using ggplot2 with a manual palette for factor levels.
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"))
The scale_color_manual function maps factor levels to colors. The factor levels "low", "medium", and "high" must be named in the values vector.