On Mon, Apr 27, 2009 at 2:58 PM, <
d.c.c...@its.leeds.ac.uk> wrote:
>
> Dear all,
>
> I would like to use coord_cartesian to zoom in on a part of a time
> series, but cannot seem to do it.
>
> Taking a similar example to Hadley's from the ggplot2 web pages:
>
> df <- data.frame(date = seq(Sys.Date(), len=100, by="1 day")[sample
> (100, 50)], price = runif(50))
> df <- df[order(df$date), ]
> qplot(date, price, data=df, geom="line")
>
> plots a nice time series.
>
> To extract part of it, which also works:
>
> qplot(date, price, data=df, geom="line") + scale_x_date(limits = c
> (as.Date("2009-04-27"), as.Date("2009-06-09")))
>
> But what if I just want to zoom in on a date range (scale_x_date will
> drop data outside the range)? I had thought this would work:
>
> qplot(date, price, data=df, geom="line") + coord_cartesian(xlim = c
> (as.Date("2009-04-27"), as.Date("2009-06-09")))