scale_x_date and expand

440 views
Skip to first unread message

smu

unread,
Feb 3, 2010, 11:34:33 AM2/3/10
to ggp...@googlegroups.com
Hi,

the scale_x_date or scale_x_datetime functions don't implement the
expand parameter that is used in other scale... functions to modify the
empty space left and right to the plots content.

Is there any workaround to remove the empty space, wenn x is a Date
object (besides transforming it to a continuous variable and setting the
labels manually)?

thank you

example:

library(ggplot)
d = data.frame(x=seq.Date(as.Date("2000-01-01"),
as.Date("2005-01-01"),by="days"),y=1:1828)

# scale_x_continuous works
ggplot(d,aes(y,y)) + geom_line() + scale_x_continuous("",expand=c(0,0))
# doesn't work
ggplot(d,aes(x,y)) + geom_line() + scale_x_datetime("",expand=c(0,0))

# empty space on the left and right side
ggplot(d,aes(x,y)) + geom_line() +
scale_x_datetime("",limits=c(as.Date("2000-01-01"),as.Date("2005-01-01")))


regards,
stefan

hadley wickham

unread,
Feb 3, 2010, 11:10:17 PM2/3/10
to ggp...@googlegroups.com
Hi Stefan,

scale_datetime doesn't use expand - it always rounds down on the left
and up on the right so that a major break occurs outside the range of
the data. Could you give me an example where this isn't what you
want?

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

--
http://had.co.nz/

smu

unread,
Feb 4, 2010, 3:43:00 AM2/4/10
to hadley wickham, ggp...@googlegroups.com
Hi Hadley,

I would like to plot a large timeserie and a smaller plot with only a
subset of the large timeserie, to show some effect which is invisible in
the low resolution plot. These two plots should be combined into one, I
am doing this with inkscape till now.

something like this:
http://z107.de/uni/ggplot_example_expand.pdf

In this case I would prefere the expand=c(0,0) in the smaller plot, to
use the available space for the data and to make it more clear that this
is only a subset.

Best regards,
stefan

hadley wickham

unread,
Feb 4, 2010, 8:39:55 AM2/4/10
to hadley wickham, ggp...@googlegroups.com
Oh, I see what you mean. It will be fixed in the next version of
ggplot2 (hopefully to be released later this week)

Hadley

--
http://had.co.nz/

smu

unread,
Feb 4, 2010, 9:57:19 AM2/4/10
to ggp...@googlegroups.com
cool, thank you.

best regards,
stefan

Reply all
Reply to author
Forward
0 new messages