Closed mkoohafkan closed 3 months ago
I'm not sure if I'm understanding the issue correctly.
Is the issue that scale_colour_date()
(which is what unspecified defaults to based on the data type) has different label formatting than scale_colour_continuous()
?
@teunbrand, yeah basically I would expect adding scale_color_continuous()
with no arguments to the above plot would have the same result as not specifying a scale_color*()
call at all, so these two plots to be identical:
p1 = ggplot(dummy) +
aes(x = x, y = y, color = date) +
geom_point()
p2 = p1 + scale_color_continuous()
# p1, p2 produce a visually identical plot
I guess the other way to phrase the issue is that I'm surprised by the automatic scales::transform_date()
when no color scale is specified at all.
I can understand the confusion as the scale system is sort-of a mixup between scale types (e.g. scale_colour_date()
) and scale palettes (e.g. scale_colour_brewer()
). Maybe this date behaviour surprises you, but I'm sure people are familiar with character/factor variables invoking different default scales than numeric variables. What would you propose to change?
oh wow, I had no idea scale_color_date()
existed! So that explains that. Note that this is not an issue of factor vs numeric (in this example both cases interpret date as continuous), it is what default transformation is being used.
Maybe this would be too verbose, but it would be neat if we could get informed what defaults where being used (similar to how {dplyr}
informs you when you don't specify by
in join functions or .groups
in summarize()
), e.g.
p1 = ggplot(dummy) +
aes(x = x, y = y, color = date) +
geom_point()
## Using `scale_color_date()`
The factor vs numeric is the exact same mechanism that lets the date class pick scale_colour_date()
instead of scale_colour_continuous()
, namely through the scale_type()
methods.
I'm not sure that increasing the verbosity is a move welcomed by most. Default scales are implied in >50% all plots I'd bet, so this would create some distraction while not requiring user intervention.
> ggplot2:::scale_type(Sys.Date())
[1] "date" "continuous"
Fair point that increasing verbosity is maybe not the way to go. I'll go ahead and close this issue.
The issue is closed already, but I also wanted to second not making ggplot2 more verbose. In my experience teaching ggplot2 to many hundreds of students, I have observed over and over again that they interpret these types of informative messages as errors. While these messages can be helpful to advanced users, they are scary to beginners.
I agree with what Claus is saying in principle. There are a few informative messages that bully users into doing the right thing and I think those can be useful. E.g. geom_histogram()
bullies people into setting (better) bins
or binwidth
and likewise geom_smooth()
begs to declare formula
/method
.
consider the following dummy data:
When I specify
color = date
aesthetic without a correspondingscale_color_*()
function, I get a nice color bar guide with breaks by year:However, when I specify
scale_color_continous()
orscale_color_gradient()
, I lose the label formatting on the color bar guide:The first result is accomplished explicitly with
The issue isn't so much that
scale_color_*()
doesn't automatically format by date, but rather that the (arguably better) unspecified color scale behavior is different from a plainscale_color_continuous()
.