[R] Time series plot with Date/Time showing on x-axis

Jim Lemon drjimlemon at gmail.com
Wed Mar 16 09:27:03 CET 2016


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.



More information about the R-help mailing list