plot - Create mulitple line chart in R -
i have following dummy data.
set.seed(45) df <- data.frame(x=rep(1:5, 9), val1=sample(1:100,45), val2=sample(1:100,45),variable=rep(paste0("category",1:9),each=5))
i plot val1 , val2 based on x (which in real data sequence of date values). how can accomplish this. have tried ggplot2, mplot, , plot without success. have looked @ other similar posts not work or address needs.
thank you.
more ggplot2
options, without reshaping data
## on 1 ggplot(df, aes(x, val1, color=variable, linetype="a")) + geom_line() + geom_line(aes(x, val2, color=variable, linetype="b")) + theme_bw() + ylab("val") + scale_linetype_manual(name="val", labels=c("val1", "val2"), values=1:2)
## faceted ggplot(df, aes(x, val1, color=variable, linetype="a")) + geom_line() + geom_line(aes(x, val2, color=variable, linetype="b")) + theme_bw() + ylab("val") + guides(color=false) + scale_linetype_manual(name="val", labels=c("val1", "val2"), values=1:2) + facet_wrap(~variable)
Comments
Post a Comment