Jim mikeself
2012-Sep-25 13:07 UTC
[R] geom_line: How to plot two data sets having different maximum X-axis values in a single plot?
Hello, I just started to learn R and ggplot2. Can someone help? How to plot two data sets having different maximum X-axis values in a single plot? For example, I have two data sets showed below. Using position as X, and count as Y, how can I plot them out in different color lines within a single plot using ggplot2 geom_line? dataset a: position count 1 3 2 9 3 10 4 15 5 19 6 28 7 15 8 13 9 11 10 5 dataset b: position count 1 4 2 8 3 16 4 17 5 19 6 10 Thanks a lot! Jim [[alternative HTML version deleted]]
John Kane
2012-Sep-26 15:36 UTC
[R] geom_line: How to plot two data sets having different maximum X-axis values in a single plot?
Clumsy but this should do it. aa$set <- rep("a", length(aa$position)) bb$set <- rep("b", length(bb$position)) (mydata <- rbind(aa,bb)) p <- ggplot( mydata , aes( position, count, colour = set )) + geom_line() p John Kane Kingston ON Canada> -----Original Message----- > From: jimmikeself at gmail.com > Sent: Tue, 25 Sep 2012 09:07:24 -0400 > To: r-help at r-project.org > Subject: [R] geom_line: How to plot two data sets having different > maximum X-axis values in a single plot? > > Hello, I just started to learn R and ggplot2. Can someone help? > > How to plot two data sets having different maximum X-axis values in a > single plot? > > For example, I have two data sets showed below. Using position as X, and > count as Y, how can I plot them out in different color lines within a > single plot using ggplot2 geom_line? > > > > dataset a: > > position count > > 1 3 > > 2 9 > > 3 10 > > 4 15 > > 5 19 > > 6 28 > > 7 15 > > 8 13 > > 9 11 > > 10 5 > > > > dataset b: > > position count > > 1 4 > > 2 8 > > 3 16 > > 4 17 > > 5 19 > > 6 10 > > > > Thanks a lot! > > > > > Jim > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Possibly Parallel Threads
- Splitting a character vector.
- Probit cluster-robust standard errors
- ggplot2 with separate average lines
- ggpliot2: reordering of factors in facets facet.grid(). Reordering of factor on x-axis no problem.
- Ggplot2: Moving legend, change fill and removal of space between plots when using grid.arrange() possible use of facet_grid?