Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve datetime scales #2186

Merged
merged 7 commits into from
Jul 7, 2017
Merged

Improve datetime scales #2186

merged 7 commits into from
Jul 7, 2017

Conversation

karawoo
Copy link
Member

@karawoo karawoo commented Jun 29, 2017

Related to #1526. This PR:

  • Renames scale_datetime() to datetime_scale() and generalizes it for use with other scales besides x/y position.
  • Uses the new datetime_scale() for size, colour, fill, and a newly created alpha scale. These scales can now all take date_breaks and date_labels parameters.

I also tidyverse style-ified scale_(x|y)_date and scale_(x|y)_datetime.


# x/y position aesthetics should use ScaleContinuousDate or
# ScaleContinuousDatetime; others use ScaleContinuous
if (all(aesthetics %in% c("x", "xmin", "xmax", "xend", "y", "ymin", "ymax", "yend"))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best way to choose the appropriate super class...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why we use ScaleContinuous for the non-position scales?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so the data will get rescaled correctly, I think. ScaleContinuous uses scales::rescale() to map the data values to the right place on the scale. For position scales this isn't needed because the coordinate system handles it.

@karawoo karawoo requested a review from hadley June 29, 2017 21:19
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests for date/time scales?


# x/y position aesthetics should use ScaleContinuousDate or
# ScaleContinuousDatetime; others use ScaleContinuous
if (all(aesthetics %in% c("x", "xmin", "xmax", "xend", "y", "ymin", "ymax", "yend"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why we use ScaleContinuous for the non-position scales?

@karawoo
Copy link
Member Author

karawoo commented Jul 4, 2017

There are a few existing tests for datetime scales, mostly they check that timezones are correct. I can add some more.

@karawoo
Copy link
Member Author

karawoo commented Jul 5, 2017

I just realized that with this will make colour/fill scales behave differently for datetimes than for other continuous variables because they won't be controlled by the global options ggplot2.continuous.colour and ggplot2.continuous.fill from #2178.

@hadley
Copy link
Member

hadley commented Jul 7, 2017

Oh hmmmm, how hard would it be to respect that option?

@karawoo
Copy link
Member Author

karawoo commented Jul 7, 2017

It's a little tricky because scale_colour_gradient() and scale_colour_viridis_c() don't take the date_breaks and date_labels parameters. I guess we'd need scale_colour_gradient_date() and scale_colour_viridis_date() (+ comparable fill scales, and datetime scales), and then scale_colour_date() can choose the right one among those. Does that sound too unwieldy?

@hadley
Copy link
Member

hadley commented Jul 7, 2017

That seems like a lot of work for little gain. Let's leave off for now and wait to see if anyone notices/complains.

@karawoo karawoo merged commit 32e699e into tidyverse:master Jul 7, 2017
karawoo added a commit to karawoo/ggplot2 that referenced this pull request Jul 14, 2017
* Rewrite scale_datetime and update position/size/alpha scales

* Fix style for scale_(x|y)_(date|datetime)

* Update fill and colour scales for datetimes

* Add to NEWS.md

* Test new datetime alpha/size/colour scales

* Test should use scale_colour_datetime, not scale_colour_gradient
@lock
Copy link

lock bot commented Jan 18, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants