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) 

enter image description here

## 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) 

enter image description here


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -