"Brian \"Meyer\" Waismeyer" <
meye...@gmail.com> writes:
> To consolidate the discussion and make comparison easy, I'm reporting the
> three code variations below and attaching PNGs of each graph they code
> produced. I comment on how each piece of code behaved for me and then I add
> some additional thoughts and attempts at producing the behavior Bill seems
> to be going for. (Note: I double checked that my R and packages were all
> updated. My timezone is PST.)
Thanks, Brian. I think what you did may help move us forward.
>> sampleDF
> time values
> 1 2013-05-01 12:00:00 3
> 2 2013-05-02 18:00:00 4
> 3 2013-05-03 06:00:00 2
>
> *Here's the first plot code (as provided by Bill):*
> qplot(time, values, data =
> sampleDF)+scale_x_datetime(minor_breaks=date_breaks("6 hour"))
>
> - on my computer: major/minor breaks are oddly aligned so that minor breaks
> don't nicely parse the space between the major breaks - this makes the
> spacing look "uneven" (similar to Bill to I think)
I was going to attach my results, but this graph is the same as the one
you provided. I perceive the data is at the correct times, as indicated
by the abscissa legend, but the minor breaks are in unexpected places.
> *Here's the first solution proposed (as provided by Hadri):*
> qplot(time, values, data = sampleDF) + scale_x_datetime(limits =
> c(min(timelist), max(timelist)), minor_breaks=date_breaks("6 hour"))
>
> - on my computer: major/minor breaks are still oddly aligned and space
> still looks uneven (similar to Bill I think). in fact, I see no changes
> from the graph produced by the original code.
I presume you intended what Hadri suggested in his first email of
2013-06-04 and showed in a graph in his second email of 2013-06-04.
That's not what I saw in his graph. For example, it has an ordinate of
4 at what I read as 3:00 a.m. on May 3, according to the graph's
abscissa, while my graph and the data frame shows it at 6 p.m. on May 2.
Your graph looked the same as mine, though. That leads me to speculate
that it has something to do with local time zones. The difference
between Hadri's time zone and yours and mine is 9 hours--the same as the
difference in the abscissa of that example point. I haven't looked at
the code, but I didn't see anything in the help text that describes how
to set time zones for scales (and breaks and vlines and ...).
> *Here's the second solution proposed (as provided by Hadri):*
> qplot(time, values, data = sampleDF)+scale_x_datetime(breaks=date_breaks("6
> hour"), minor_breaks = date_breaks("3 hour"))
>
> - on my computer: the space is now evenly parsed but the major breaks seem
> oddly placed (on 21, 3, 9, ... instead of 0, 6, 12, ...).
Agreed.
> Even though this solution works, I'm still confused as to why the breaks
> lined up so oddly in the first place. I suspect this solution simply masks
> the mis-alignment going on between the major/minor breaks by having the
> minor breaks "overfill."
>
> For instance, I think Bill wanted this:
> major minor
> 0 0
>
> 6
>
> 12 12
Right.
> But got this:
> major minor
> 0
> 3
>
> 9
> 12
Yes.
> The current solution gives this:
> major minor
> 0
> 3 3
> 6
> 9 9
> 12
>
> The mis-alignment is still there - we've just masked it by having the minor
> breaks fill in the gaps.
>
> In fact, reading through ??scale_x_datetime, I am confused why the
> following doesn't work to give the behavior Bill seems to want.
> *
> *
> *third solution (using the default minor breaks)*
> qplot(time, values, data =
> sampleDF)+scale_x_datetime(breaks=date_breaks("12 hour"))
>
> The major breaks occur every 12 hours with a minor break marked in between
> each (the default behavior when minor breaks aren't specified) at the 6
> hour marks. This is the correct spacing and has removed the major/minor
> misalignment. However, now the grid lines up poorly with the data and (at
> least to me) the breaks seem illogical since they are at odd times (21, 3,
> 9, ...).
>
> I think this is what Hadri's first solution was attempting to address - by
> adjusting the start/end points of the scale to the min/max values, we
> should get better aligned breaks. Yet this doesn't work as anticipated - it
> doesn't change my graph at all. I think the graph already assigned these
> values as default.
>
> Perhaps it's the "expand" feature of scale_x_datetime? This feature seems
> to put space between the min/max values on the scale and the edges of the
> drawn grid. I wasn't able to figure out how to make "expand" work directly,
> but I was able to "force" the data into the desired alignment by adjusting
> the values in "limits".
>
> *fourth solution (shifting the scale minimum to line up the first time with
> a major break)*
> qplot(time, values, data =
> sampleDF)+scale_x_datetime(breaks=date_breaks("12 hour"), limits =
> c(as.POSIXct("2013-05-01 3:00:00 PDT"), as.POSIXct("2013-05-03 08:00:00
> PDT")))
>
> The main problem with this "solution" is that it draws too much of the
> range before the first data-point... =/
... and it also makes ggplot hard to use, but most of ggplot is easy and
intuitive, at least after a bit of learning.
> I still suspect that "expand" might be the place to look for an alignment
> solution...
>
> And that's where I stopped for the day. =)
Me, too. :-)
Does this spark any ideas?