I often run into an issue where I have a data frame that has a single x variable, one or more facet variables, and multiple different other variables. Sometimes I would lik
ggplot always prefers long format dataframe, so melt
it:
library(reshape2)
mtcars.long <- melt(mtcars, id = "mpg", measure = c("disp", "hp", "wt"))
ggplot(mtcars.long, aes(mpg, value, colour = variable)) + geom_line()
There are many other options for doing this transformation. You can see the R-FAQ on converting data from wide to long for an overview.