cmkimber / bikeshare-to

Bike Share Toronto Analysis and Reports
0 stars 0 forks source link

pane 4 monthly and daily plots require jittering #23

Open cmkimber opened 2 months ago

cmkimber commented 2 months ago

As the monthly and daily line plots on pane 4 show 2 user types and their sum, there are issues with heavy overlap between the line types. This is particularly noticable with daily data for less heavily used stations where only one user type patronizes the station, meaning 100% overlap between that user type and the total line. The user type involved cannot be ascertained from the plot in these instances (though the monthly plot makes it clear).

Adding jitter to the geoms should fix this, but both geom_line and geom_point need the same jitter so as to match. This should be possible with setting seeds for the jitter but needs debugging.

cmkimber commented 2 months ago

Monthly plots have been fixed by creating a jitterer object using position_jitter() with a seed set and calling that jitterer in both geoms.

Currently jittering is not working in the daily graphs for yet to be determined reasons. position_jitter() jitterer object does not work when called in either geom and direct calls to position_jitter() within the geom do not work either. Trying to understand what it is about the underlying data that is not working.

cmkimber commented 2 months ago

Making some progress on understanding the issue with the daily graph. The problem seems to involve setting the width in position_jitter. Using either geom_jitter_interactive or position = "jitter" in geom_point_interactive with defaults settings jitters the points in the daily graph. Using position_jitter with defaults for width but height = 0, seed = 123 jitters the points in the X axis, but any value for width between 0 and 0.5 produces no jittering.

Jittering in ggplot2 is a function of the graph's resolution as defined by resolution() in ggplot2, but POSIXt objects do not have a resolution as they are non-numeric. Not sure how jittering is being calculated for these objects when defaults are used but this is probably related to why jittering with a specified width does not work correctly.