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

the default value of ScaleBinned$n.breaks should be 4, not 5. #3580

Closed

Conversation

microly
Copy link
Contributor

@microly microly commented Oct 21, 2019

The default value of ScaleBinned$n.breaks was set to the same as trans objects.
The default value of trans objects can map data to 5 colours in plot and legend, which is a direct-viewing color display.

However, when n.breaks is set to 5, ScaleBinned will map the data to 6 colours!
6 colours display is not so good as 5 colours.

This occur in the codes:

breaks <- sort(unique(c(limits[1], breaks, limits[2])))

and
pal <- self$palette(breaks[-1] - diff(breaks) / 2)

So I think the default value of ScaleBinned$n.breaks should be 4, not 5, then it can works the same way as trans objects.

@thomasp85 , please consider it, thanks!

The default value of ScaleBinned$n.breaks was set to the same as trans objects.
The default value of trans objects can map data to 5 colours in plot and legend, which is a direct-viewing color display.

However, when n.breaks is set to 5, ScaleBinned will map the data to 6 colours!
This occur in the codes:
https://github.com/tidyverse/ggplot2/blob/115c3960d0fd068f1ca4cfe4650c0e0474aabba5/R/scale-.r#L914
and
https://github.com/tidyverse/ggplot2/blob/115c3960d0fd068f1ca4cfe4650c0e0474aabba5/R/scale-.r#L928

So I think the default value of ScaleBinned$n.breaks should be 4, not 5, then it can works the same way as trans objects.
@clauswilke
Copy link
Member

Could you provide a reprex that demonstrates the problem with the current code base?

@microly
Copy link
Contributor Author

microly commented Oct 21, 2019

@clauswilke
Sure!

I have not used reprex before.
I will learn it and provide a demonstration soon.

@microly
Copy link
Contributor Author

microly commented Oct 23, 2019

@clauswilke
I try to use the reprex package.
However, because of the government regulation of Internet, I cannot connect to "imgur.com" from the mainland of China.
So I have to supply graphic examples by hand.

@batpigandme
Copy link
Contributor

batpigandme commented Oct 23, 2019

Ah @microly, the GFW issue with reprex/imgur is unfortunate, and known.
tidyverse/reprex#220 (comment)
In lieu of running an actual reprex, could you give the full code for your example so one of us could run it locally?

There is an open issue in reprex in hopes of resolving this one day: tidyverse/reprex#214

@microly
Copy link
Contributor Author

microly commented Oct 23, 2019

Here are the examples:

By now, The default value of ScaleBinned$n.breaks is 5.

Scale_fill_fermenter (which based on ScaleBinned) has six colours in the legend, which is different from scale_fill_distiller (which based on ScaleContinuous).

After setting ScaleBinned$n.breaks to 4, it works the same way like scale_fill_distiller, both of which have 4 colours in their legends.

library(ggplot2)
library(tibble)

ggplot(tibble(x = 1:10, y = x, z = x), aes(x, y, fill = z)) +
    geom_point(shape = 21, size = 10) +
    scale_fill_fermenter(trans = "identity", nice.breaks = F,
                         n.breaks = 5,
                         guide = "legend")

p1

ggplot(tibble(x = 1:10, y = x, z = x), aes(x, y, fill = z)) +
    geom_point(shape = 21, size = 10) +
    scale_fill_fermenter(trans = "identity", nice.breaks = F,
                         n.breaks = 4,
                         guide = "legend")

p2

ggplot(tibble(x = 1:10, y = x, z = x), aes(x, y, fill = z)) +
    geom_point(shape = 21, size = 10) +
    scale_fill_distiller(trans = "identity",
                         guide = "legend")

p3

@microly
Copy link
Contributor Author

microly commented Oct 23, 2019

@batpigandme
Thanks for your kind reply!
I past the example codes above.
I think it can be saw now.

@thomasp85
Copy link
Member

We are pending an update to the scales package before we can actually pass n.breaks forward. The current values are not expected to make it to the release, but we will wait to change it until it has an effect

@microly
Copy link
Contributor Author

microly commented Oct 25, 2019

OK, thanks for your reply~

@thomasp85
Copy link
Member

I am closing this. The default of 5 makes sense as you'd generally want a break in the middle of your range instead of having a bin that spans over the middle. You shouldn't use the legend guide with a binned scale as it does not communicate the actually scale. Use the 'bins' guide instead

@thomasp85 thomasp85 closed this Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants