I\'d like to plot multiple lines in R for this dataset: (x = Year, y = Value)
School_ID Year Value
A 1998 5
B 1998 10
C
The plot function in base R does not support grouping so you need to display your groups one by one. GGPLOT handles grouping well. I also suggest looking at Trellis XYPLOT which allows you to plot separate groups.
This is how you can create a basic grouped line plot using Trellis:
library(lattice)
rm(list = ls()) # clear objects
graphics.off() # close graphics windows
test = data.frame(x = rep(1:3, each = 2),
group = rep(c("Group 1","Group 2"),3),
y= c(22,8,11,4,7,5)
)
xyplot(y~x,
type="b",
group=group,
data=test,
auto.key =list(
points = FALSE,
columns=2,
lines = TRUE)
)