Alex
Alex

Reputation: 15708

Make date tick marks align properly with plotted data points in ggvis

Consider the following two plots made from this data frame:

temp = data.frame(x = seq(as.Date('2014-08-01'),as.Date('2014-08-30'),by=1), 
                  y = 1:30,
                 x2 = 1:30)

There is no problem using ggvis to plot vectors which are not dates:

temp %>%
    ggvis(~x2,~y) %>%
    layer_points()

Points plotted correctly when x-axis is not a date

However, when we try to use a date (in this case in the x-axis), we see that the tick marks no longer align with the plotted points.

temp %>%
    ggvis(~x,~y) %>%
    layer_points()

Points not correctly aligned with respect to x-axis tick marks when x-axis is a date

I am guessing this is some sort of bug, but in the interim, it seems like we can fix it by moving the x-axis ticks by a certain amount, but I do not know what this amount is, nor do I know how to move the tick marks.

Upvotes: 2

Views: 279

Answers (1)

PirateR
PirateR

Reputation: 37

I've found that setting the time to 6:00 am for every observation in the data "fixes" the issue so that it aligns with the date tick marks. E.g. Date variable:

 [1] "12/27/2015 6:00:00" "12/29/2015 6:00:00" "12/26/2015 6:00:00" "12/30/2015 6:00:00"
 [5] "12/31/2015 6:00:00" "12/28/2015 6:00:00" "12/31/2015 6:00:00" "12/29/2015 6:00:00"
 [9] "12/30/2015 6:00:00" "12/31/2015 6:00:00" "12/26/2015 6:00:00" "12/28/2015 6:00:00"

Upvotes: 1

Related Questions