Skip to content
Prev 154965 / 398506 Next

ggplot2: line plot with gaps in time axis

Brian,

The easiest way is to create the entire timeseries and then set the
missing values to NA. The NA values will lead to the gaps you want.

HTH,

Thierry 


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens btcruiser
Verzonden: woensdag 3 september 2008 20:33
Aan: r-help op r-project.org
Onderwerp: [R] ggplot2: line plot with gaps in time axis


Hello, I'm trying to plot data that has gaps in the timeline because my
data
only has the business day in it. When I do a line plot I get the data
and
then a blank area where a line goes the tail of the last data point  to
the
head of the next data point. Is there a way I can do a line plot where
the
gaps are not plotted?

Thanks in advance, 

Brian
[1] "Date_and_Time" "Utilization"   "Direction"
Date_and_Time Utilization Direction
1    2008-08-25 05:00:00    5.862601   Inbound
2    2008-08-25 05:05:00   10.025328   Inbound
3    2008-08-25 05:10:00    5.794900   Inbound
4    2008-08-25 05:15:00    9.862726   Inbound
5    2008-08-25 05:20:00    4.150328   Inbound
6    2008-08-25 05:25:00    5.559362   Inbound
[...]

# startDateTime and stopDateTime is user entered
Start <- as.numeric(as.POSIXct(startDateTime))
End <- as.numeric(as.POSIXct(stopDateTime))
Period<-as.numeric(seq.POSIXt(as.POSIXct(Start,origin="1970-1-1"),
as.POSIXct(End,origin="1970-1-1"), by="DSTday"))
Labels<-as.Date(seq.POSIXt(as.POSIXct(Start,origin="1970-1-1"),
as.POSIXct(End,origin="1970-1-1"), by="DSTday"))
dt <-
qplot(as.numeric(utildf$Date_and_Time),Utilization,data=utildf,colour=Di
rection,geom="segment")
dt + scale_x_continuous(breaks=Period,label=Labels)