Eike Marie Thaysen
2013-Feb-09 12:52 UTC
[R] help on plotting series with different x-axis values on a graph with one x-axis
Hi, I have run into this problem a couple of times now and hope you can help! If I want to plot mulitiple series with differing x-axis values (however, all in the same range) in 1 plot with one common axis R obstruses the plots. E.g. if I plot water content against time and I start with the sampler at 5 cm depth, it plots that one right. But the next depth, 15 cm, is measured at slightly different time intervals and so R will not plot the series correctly. Reading in the data using ? stringsAsFactors=FALSE? helps, but the lines are still plottet in an akward fashion (edgy) , see attached image. Hope you can help! eike Eike Marie Thaysen Ph.d. studerende ECO Institut for Kemiteknik DTU Danmarks Tekniske Universitet [dtu] Ris? Campus Frederiksborgvej 399 Bygning 309 4000 Roskilde Telefon: 51801481 emth at kt.dtu.dk<mailto:emth at risoe.dtu.dk> www.dtu.dk<http://www.risoe.dtu.dk/>
David Winsemius
2013-Feb-09 15:49 UTC
[R] help on plotting series with different x-axis values on a graph with one x-axis
On Feb 9, 2013, at 4:52 AM, Eike Marie Thaysen wrote:> > Hi, > I have run into this problem a couple of times now and hope you can > help! > > If I want to plot mulitiple series with differing x-axis values > (however, all in the same range) in 1 plot with one common axis R > obstruses the plots. > > E.g. if I plot water content against time and I start with the > sampler at 5 cm depth, it plots that one right. > But the next depth, 15 cm, is measured at slightly different time > intervals and so R will not plot the series correctly. > Reading in the data using ? stringsAsFactors=FALSE? helps, but the > lines are still plottet in an akward fashion (edgy) , see attached > image. > Hope you can help! > eikeNo image was attached. It was probably in a format the the mail server would not accept. PDF files are the only one listed as being acceptable, but I think from experience that PNG files might also make it through. It would probably also help if you offered the output of str(dfrm) on whateever dataframe you are working with. -- David.> > > > Eike Marie Thaysen > > Ph.d. studerende > > ECO > > Institut for Kemiteknik DTU > > Danmarks Tekniske Universitet > > [dtu] > > Ris? Campus > > Frederiksborgvej 399 > > Bygning 309 > > 4000 Roskilde > Telefon: 51801481 > > > > emth at kt.dtu.dk<mailto:emth at risoe.dtu.dk> > > www.dtu.dk<http://www.risoe.dtu.dk/> > > > ______________________________________________ > 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.David Winsemius, MD Alameda, CA, USA
John Kane
2013-Feb-10 13:38 UTC
[R] help on plotting series with different x-axis values on a graph with one x-axis
No image. png files seem to make it through so if you save as png it should arrive. Some sample code and data would help Is the data in one data.frame or could you put it into one? If so you might want to try melting the data (see reshape 2 package) and plotting with ggplot2 John Kane Kingston ON Canada> -----Original Message----- > From: emth at kt.dtu.dk > Sent: Sat, 9 Feb 2013 12:52:32 +0000 > To: r-help at r-project.org > Subject: [R] help on plotting series with different x-axis values on a > graph with one x-axis > > > Hi, > I have run into this problem a couple of times now and hope you can help! > > If I want to plot mulitiple series with differing x-axis values > (however, all in the same range) in 1 plot with one common axis R > obstruses the plots. > > E.g. if I plot water content against time and I start with the sampler at > 5 cm depth, it plots that one right. > But the next depth, 15 cm, is measured at slightly different time > intervals and so R will not plot the series correctly. > Reading in the data using ? stringsAsFactors=FALSE? helps, but the lines > are still plottet in an akward fashion (edgy) , see attached image. > Hope you can help! > eike > > > > Eike Marie Thaysen > > Ph.d. studerende > > ECO > > Institut for Kemiteknik DTU > > Danmarks Tekniske Universitet > > [dtu] > > Ris? Campus > > Frederiksborgvej 399 > > Bygning 309 > > 4000 Roskilde > Telefon: 51801481 > > > > emth at kt.dtu.dk<mailto:emth at risoe.dtu.dk> > > www.dtu.dk<http://www.risoe.dtu.dk/> > > > ______________________________________________ > 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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
Jim Lemon
2013-Feb-11 10:57 UTC
[R] help on plotting series with different x-axis values on a graph with one x-axis
On 02/09/2013 11:52 PM, Eike Marie Thaysen wrote:> > Hi, > I have run into this problem a couple of times now and hope you can help! > > If I want to plot mulitiple series with differing x-axis values (however, all in the same range) in 1 plot with one common axis R obstruses the plots. > > E.g. if I plot water content against time and I start with the sampler at 5 cm depth, it plots that one right. > But the next depth, 15 cm, is measured at slightly different time intervals and so R will not plot the series correctly. > Reading in the data using ? stringsAsFactors=FALSE? helps, but the lines are still plottet in an akward fashion (edgy) , see attached image. > Hope you can help!Hi eike, I'll do a bit of guessing to see if it helps. First, I think that your times are being read in as factors (they are probably formatted like "11 Feb 2013 13:23:37" or similar and read as character strings). As you are probably sampling at fairly equal intervals, the fact that the factors are represented by integers starting with 1 may look okay. What you may want is to convert these to date/time objects (say the data frame is "mydata" and the times are "sample_time"): mydata$sample_time<-strptime(mydata$sample_time, format="%d %b %Y %H:%M:%S") or something like that. Then the x axis will be in units of date/time and your second series will be plotted correctly. By calling the lines "edgy" perhaps you mean that they are not smooth curves. You may want to use the "approx" function or a smoothing function to smooth out the lines and plot those curves instead. Having the data would help, so if you could "dput" your data or a small subset of it, we could give better suggestions. Jim