Displaying 1 result from an estimated 1 matches for "mydata_long".
2013 Jan 17
3
Getting discrete colors on plot
...1,2,3,4,5)
x1 <- c(5,2,3,5,1)
x2 <- c(4,1,3,5,1)
x3 <- c(5,2,3,5,1)
x4 <- c(4,3,3,5,1)
x5 <- c(3,1,3,5,1)
colorvar <- c(3,1,2,3,1)
mydata <- data.frame(id,x1,x2,x3,x4,x5,colorvar)
head(mydata)
# convert to long format
require("reshape")
mydata_long <- melt(mydata, id=c("id", "colorvar"))
head(mydata_long)
require("ggplot2")
p <- ggplot(data=mydata_long,
aes(x=variable, y=value,
group=id, colour = colorvar)) +
geom_line()
p
This works, but I get more colors on the graph than my colorvar has....