Multiple time-series data with missing values in a single plot using R

I have prepared a data frame ordered according to date and time as.POSIXlt:

             Date_Time A1    B2 C1    E2
46 24/06/2012 12:20:00 NA 5.515 20    NA
47 24/06/2012 13:20:00 41    NA NA 3.519
48 25/06/2012 14:00:00 NA    NA NA    NA
49 25/06/2012 14:20:00 30    NA 30    NA
50 27/06/2012 15:20:00 NA    71 NA    NA
51 28/06/2012 18:00:00 11    NA 55    11
... ...

As you can see it contains a lot of 'NA' values. Is it possible to plot all data in a single plot with the 'x-axis' showing month-year and different colors assigned for different data (e.g. green for A1, blue for C1)? I tried 'ggplot2' package which removes all missing values. Trying 'zoo' package doesn't allow x-axis to be plotted as month-year. Any suggestion?


This should not be problematic for any of R's plotting packages. I'm not a ggplot user, but here's a base R example using a slightly modified version of your data. Note that using as.POSIXct is preferable to using as.POSIXlt within data.frame objects:

dat <- read.csv(text="Date_Time,A1,B2,C1,E2
24/06/2012 12:20:00,NA,5.515,20,NA
24/06/2012 13:20:00,41,NA,NA,3.519
25/06/2012 14:00:00,NA,NA,NA,NA
25/07/2012 14:20:00,30,NA,30,NA
27/08/2012 15:20:00,NA,71,NA,NA
28/09/2012 18:00:00,11,NA,55,11")

dat$Date_Time <- as.POSIXct(dat$Date_Time,format="%d/%m/%Y %H:%M:%S")


Add a POSIXct represented axis with a chosen format:


Need Your Help

Inversion of Control, Dependency Injection and Strategy Pattern with examples in java

java spring dependency-injection inversion-of-control strategy-pattern

I am often confused by these three terms. These three look similar to me. Can someone please explain them to me clearly, with examples.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.