Kwabena Fosu-Amankwah
2016-Mar-16 03:28 UTC
[R] Time series plot with Date/Time showing on x-axis
I would be very grateful if someone can help me with the code or script on how to plot a time series plot with Date/Time showing on x-axis for the set of data below: Date/Time PR SW TP SM SHF CO2 28.11.2011 17:39:49 978.4 13.15 30.5 20 NA NA 28.11.2011 17:50:00 978.5 13.11 30.4 20 NA NA 28.11.2011 18:00:00 978.8 13.14 30.3 20 NA NA 28.11.2011 18:10:00 979 13.07 30.1 20 NA NA 28.11.2011 18:20:00 979.2 13.1 30 20 NA NA 28.11.2011 18:30:00 979.4 13.09 29.8 20 NA NA 28.11.2011 18:40:00 979.5 13.08 29.6 20 NA NA 28.11.2011 18:50:00 979.5 13.06 29.5 20 NA NA 28.11.2011 19:00:00 979.6 13.06 29.4 20 NA NA 28.11.2011 19:10:00 979.7 13.05 29.3 20 NA NA 28.11.2011 19:20:00 979.9 13.03 29.2 20 NA NA 28.11.2011 19:30:00 980 13 29.1 20 NA NA 28.11.2011 19:40:00 980 13.03 29 20 NA NA 28.11.2011 19:50:00 980.1 13.03 28.9 20 NA NA 28.11.2011 20:00:00 980.3 13 28.8 20 NA NA 28.11.2011 20:10:00 980.5 12.97 28.7 20 NA NA 28.11.2011 20:20:00 980.8 12.96 28.6 20 NA NA 28.11.2011 20:30:00 981.1 12.95 28.5 20 NA NA 28.11.2011 20:40:00 981.1 12.95 28.4 20 NA NA 28.11.2011 20:50:00 981.2 12.94 28.3 20 NA NA 28.11.2011 21:00:00 981.3 12.93 28.2 20 NA NA 28.11.2011 21:10:00 981.3 12.92 28.1 20 NA NA 28.11.2011 21:20:00 981.5 12.9 28 20 NA NA 28.11.2011 21:30:00 981.6 12.9 27.9 20 NA NA 28.11.2011 21:40:00 981.7 12.88 27.9 20 NA NA 28.11.2011 21:50:00 981.7 12.87 27.8 20 NA NA 28.11.2011 22:00:00 981.7 12.86 27.7 20 NA NA 28.11.2011 22:10:00 981.8 12.85 27.6 20 NA NA 28.11.2011 22:20:00 981.8 12.84 27.5 20 NA NA 28.11.2011 22:30:00 981.8 12.83 27.5 20 NA NA Thank you [[alternative HTML version deleted]]
Hi From your data is not clear if your first column is in POSOX format or character/factor. You can check it by ?str If it is POSIX, what is wrong in with(yourdata, plot(Date/Time, SW)) Cheers Petr> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Kwabena > Fosu-Amankwah > Sent: Wednesday, March 16, 2016 4:28 AM > To: r-help at r-project.org > Subject: [R] Time series plot with Date/Time showing on x-axis > > I would be very grateful if someone can help me with the code or script > on how to plot a time series plot with Date/Time showing on x-axis for > the set of data below: > > Date/Time PR SW TP SM SHF CO2 > 28.11.2011 17:39:49 978.4 13.15 30.5 20 NA NA > 28.11.2011 17:50:00 978.5 13.11 30.4 20 NA NA > 28.11.2011 18:00:00 978.8 13.14 30.3 20 NA NA > 28.11.2011 18:10:00 979 13.07 30.1 20 NA NA > 28.11.2011 18:20:00 979.2 13.1 30 20 NA NA > 28.11.2011 18:30:00 979.4 13.09 29.8 20 NA NA > 28.11.2011 18:40:00 979.5 13.08 29.6 20 NA NA > 28.11.2011 18:50:00 979.5 13.06 29.5 20 NA NA > 28.11.2011 19:00:00 979.6 13.06 29.4 20 NA NA > 28.11.2011 19:10:00 979.7 13.05 29.3 20 NA NA > 28.11.2011 19:20:00 979.9 13.03 29.2 20 NA NA > 28.11.2011 19:30:00 980 13 29.1 20 NA NA > 28.11.2011 19:40:00 980 13.03 29 20 NA NA > 28.11.2011 19:50:00 980.1 13.03 28.9 20 NA NA > 28.11.2011 20:00:00 980.3 13 28.8 20 NA NA > 28.11.2011 20:10:00 980.5 12.97 28.7 20 NA NA > 28.11.2011 20:20:00 980.8 12.96 28.6 20 NA NA > 28.11.2011 20:30:00 981.1 12.95 28.5 20 NA NA > 28.11.2011 20:40:00 981.1 12.95 28.4 20 NA NA > 28.11.2011 20:50:00 981.2 12.94 28.3 20 NA NA > 28.11.2011 21:00:00 981.3 12.93 28.2 20 NA NA > 28.11.2011 21:10:00 981.3 12.92 28.1 20 NA NA > 28.11.2011 21:20:00 981.5 12.9 28 20 NA NA > 28.11.2011 21:30:00 981.6 12.9 27.9 20 NA NA > 28.11.2011 21:40:00 981.7 12.88 27.9 20 NA NA > 28.11.2011 21:50:00 981.7 12.87 27.8 20 NA NA > 28.11.2011 22:00:00 981.7 12.86 27.7 20 NA NA > 28.11.2011 22:10:00 981.8 12.85 27.6 20 NA NA > 28.11.2011 22:20:00 981.8 12.84 27.5 20 NA NA > 28.11.2011 22:30:00 981.8 12.83 27.5 20 NA NA > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.________________________________ Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a jsou ur?eny pouze jeho adres?t?m. Jestli?e jste obdr?el(a) tento e-mail omylem, informujte laskav? neprodlen? jeho odes?latele. Obsah tohoto emailu i s p??lohami a jeho kopie vyma?te ze sv?ho syst?mu. Nejste-li zam??len?m adres?tem tohoto emailu, nejste opr?vn?ni tento email jakkoliv u??vat, roz?i?ovat, kop?rovat ?i zve?ej?ovat. Odes?latel e-mailu neodpov?d? za eventu?ln? ?kodu zp?sobenou modifikacemi ?i zpo?d?n?m p?enosu e-mailu. V p??pad?, ?e je tento e-mail sou??st? obchodn?ho jedn?n?: - vyhrazuje si odes?latel pr?vo ukon?it kdykoliv jedn?n? o uzav?en? smlouvy, a to z jak?hokoliv d?vodu i bez uveden? d?vodu. - a obsahuje-li nab?dku, je adres?t opr?vn?n nab?dku bezodkladn? p?ijmout; Odes?latel tohoto e-mailu (nab?dky) vylu?uje p?ijet? nab?dky ze strany p??jemce s dodatkem ?i odchylkou. - trv? odes?latel na tom, ?e p??slu?n? smlouva je uzav?ena teprve v?slovn?m dosa?en?m shody na v?ech jej?ch n?le?itostech. - odes?latel tohoto emailu informuje, ?e nen? opr?vn?n uzav?rat za spole?nost ??dn? smlouvy s v?jimkou p??pad?, kdy k tomu byl p?semn? zmocn?n nebo p?semn? pov??en a takov? pov??en? nebo pln? moc byly adres?tovi tohoto emailu p??padn? osob?, kterou adres?t zastupuje, p?edlo?eny nebo jejich existence je adres?tovi ?i osob? j?m zastoupen? zn?m?. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
Hi Kwabena, Try this: kfa.df<-read.table(text="Date/Time,PR,SW,TP,SM,SHF,CO2 28.11.2011 17:39:49,978.4,13.15,30.5,20,NA,NA 28.11.2011 17:50:00,978.5,13.11,30.4,20,NA,NA 28.11.2011 18:00:00,978.8,13.14,30.3,20,NA,NA 28.11.2011 18:10:00,979,13.07,30.1,20,NA,NA 28.11.2011 18:20:00,979.2,13.1,30,20,NA,NA 28.11.2011 18:30:00,979.4,13.09,29.8,20,NA,NA 28.11.2011 18:40:00,979.5,13.08,29.6,20,NA,NA 28.11.2011 18:50:00,979.5,13.06,29.5,20,NA,NA 28.11.2011 19:00:00,979.6,13.06,29.4,20,NA,NA 28.11.2011 19:10:00,979.7,13.05,29.3,20,NA,NA 28.11.2011 19:20:00,979.9,13.03,29.2,20,NA,NA 28.11.2011 19:30:00,980,13,29.1,20,NA,NA 28.11.2011 19:40:00,980,13.03,29,20,NA,NA 28.11.2011 19:50:00,980.1,13.03,28.9,20,NA,NA 28.11.2011 20:00:00,980.3,13,28.8,20,NA,NA 28.11.2011 20:10:00,980.5,12.97,28.7,20,NA,NA 28.11.2011 20:20:00,980.8,12.96,28.6,20,NA,NA 28.11.2011 20:30:00,981.1,12.95,28.5,20,NA,NA 28.11.2011 20:40:00,981.1,12.95,28.4,20,NA,NA 28.11.2011 20:50:00,981.2,12.94,28.3,20,NA,NA 28.11.2011 21:00:00,981.3,12.93,28.2,20,NA,NA 28.11.2011 21:10:00,981.3,12.92,28.1,20,NA,NA 28.11.2011 21:20:00,981.5,12.9,28,20,NA,NA 28.11.2011 21:30:00,981.6,12.9,27.9,20,NA,NA 28.11.2011 21:40:00,981.7,12.88,27.9,20,NA,NA 28.11.2011 21:50:00,981.7,12.87,27.8,20,NA,NA 28.11.2011 22:00:00,981.7,12.86,27.7,20,NA,NA 28.11.2011 22:10:00,981.8,12.85,27.6,20,NA,NA 28.11.2011 22:20:00,981.8,12.84,27.5,20,NA,NA 28.11.2011 22:30:00,981.8,12.83,27.5,20,NA,NA", sep=",",header=TRUE,stringsAsFactors=FALSE) kfa.df$Date.Time<-strptime(kfa.df$Date.Time,"%d.%m.%Y %H:%M:%S") library(plotrix) plot(kfa.df$Date.Time,kfa.df$PR,xaxt="n") xticklab<-pretty(kfa.df$Date.Time) staxlab(1,at=xticklab) Jim On Wed, Mar 16, 2016 at 2:28 PM, Kwabena Fosu-Amankwah <fosu77 at gmail.com> wrote:> I would be very grateful if someone can help me with the code or > script on how to plot a time series plot with Date/Time showing on > x-axis for the set of data below: > > Date/Time PR SW TP SM SHF CO2 > 28.11.2011 17:39:49 978.4 13.15 30.5 20 NA NA > 28.11.2011 17:50:00 978.5 13.11 30.4 20 NA NA > 28.11.2011 18:00:00 978.8 13.14 30.3 20 NA NA > 28.11.2011 18:10:00 979 13.07 30.1 20 NA NA > 28.11.2011 18:20:00 979.2 13.1 30 20 NA NA > 28.11.2011 18:30:00 979.4 13.09 29.8 20 NA NA > 28.11.2011 18:40:00 979.5 13.08 29.6 20 NA NA > 28.11.2011 18:50:00 979.5 13.06 29.5 20 NA NA > 28.11.2011 19:00:00 979.6 13.06 29.4 20 NA NA > 28.11.2011 19:10:00 979.7 13.05 29.3 20 NA NA > 28.11.2011 19:20:00 979.9 13.03 29.2 20 NA NA > 28.11.2011 19:30:00 980 13 29.1 20 NA NA > 28.11.2011 19:40:00 980 13.03 29 20 NA NA > 28.11.2011 19:50:00 980.1 13.03 28.9 20 NA NA > 28.11.2011 20:00:00 980.3 13 28.8 20 NA NA > 28.11.2011 20:10:00 980.5 12.97 28.7 20 NA NA > 28.11.2011 20:20:00 980.8 12.96 28.6 20 NA NA > 28.11.2011 20:30:00 981.1 12.95 28.5 20 NA NA > 28.11.2011 20:40:00 981.1 12.95 28.4 20 NA NA > 28.11.2011 20:50:00 981.2 12.94 28.3 20 NA NA > 28.11.2011 21:00:00 981.3 12.93 28.2 20 NA NA > 28.11.2011 21:10:00 981.3 12.92 28.1 20 NA NA > 28.11.2011 21:20:00 981.5 12.9 28 20 NA NA > 28.11.2011 21:30:00 981.6 12.9 27.9 20 NA NA > 28.11.2011 21:40:00 981.7 12.88 27.9 20 NA NA > 28.11.2011 21:50:00 981.7 12.87 27.8 20 NA NA > 28.11.2011 22:00:00 981.7 12.86 27.7 20 NA NA > 28.11.2011 22:10:00 981.8 12.85 27.6 20 NA NA > 28.11.2011 22:20:00 981.8 12.84 27.5 20 NA NA > 28.11.2011 22:30:00 981.8 12.83 27.5 20 NA NA > > Thank you > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.