Complete the code to create a basic line plot using ggplot2.
library(ggplot2) data <- data.frame(x = 1:5, y = c(3, 5, 2, 8, 7)) ggplot(data, aes(x = x, y = y)) + [1]()
The geom_line() function adds a line plot layer to the ggplot.
Complete the code to map the color aesthetic to the variable 'group' in the line plot.
library(ggplot2) data <- data.frame(x = rep(1:5, 2), y = c(3,5,2,8,7,4,6,3,7,9), group = rep(c('A', 'B'), each = 5)) ggplot(data, aes(x = x, y = y, color = [1])) + geom_line()
Mapping color = group colors the lines by the 'group' variable.
Fix the error in the code to correctly plot lines grouped by 'group'.
library(ggplot2) data <- data.frame(x = rep(1:5, 2), y = c(3,5,2,8,7,4,6,3,7,9), group = rep(c('A', 'B'), each = 5)) ggplot(data, aes(x = x, y = y, color = group)) + geom_line(aes(group = [1]))
Setting group = group inside geom_line() ensures lines connect points within each group.
Fill both blanks to create a line plot with points and set line type by 'group'.
library(ggplot2) data <- data.frame(x = rep(1:4, 2), y = c(2,4,3,5,3,5,4,6), group = rep(c('X', 'Y'), each = 4)) ggplot(data, aes(x = x, y = y, [1] = group)) + geom_line() + geom_point(aes([2] = group))
Use linetype = group to change line styles by group, and shape = group to change point shapes by group.
Fill all three blanks to create a line plot with customized color, line type, and add a title.
library(ggplot2) data <- data.frame(time = 1:6, value = c(5,7,6,8,7,9), category = rep(c('A', 'B'), each = 3)) ggplot(data, aes(x = time, y = value, color = [1], linetype = [2])) + geom_line() + ggtitle([3])
Mapping both color and linetype to 'category' differentiates lines by category. The title is set with a string.