how to plot NA gaps using ggplot2

In basic plotting in R if there is an NA in a data series ggplot2 a gap will be plotted:

As an example see:


However, ggplot2 removes the missing values and plots a straight line with no gap.


I'd like to keep the gaps. They are valuable info in the data I am working with. Is there a simple way to tell ggplot2 to stop ignoring gaps?


This happens because you set both x and y to NA. (And the ggplot2 behaviour is more sensible IMHO than the base plot behaviour.) If only the y values are NA, you get the desired behaviour. Here is a workaround:

df$g <- cumsum(apply(df, 1, anyNA))
ggplot(data=df,aes(x,y, group=g))+geom_line()

Replace geom_line with geom_path.

ggplot(data = df, aes(x, y)) +

Need Your Help

Linq orderby national character sets

linq internationalization order generic-list

I have a List which i OrderBy alfabetically on a property.

Cache UIViewController for presentation/pushing

ios model-view-controller caching uiviewcontroller uinavigationcontroller

Is it possible/practical/beneficial to cache UIViewControllers at the startup of an app so that when they need to be presented (or pushed by a UINavigationController), the memory does not have to be

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.