Closed Olivia-Box-Power closed 2 weeks ago
scale defaults cannot be updated in the same way we do for geom defaults. It requires a lengthy wrapper function that checks what kind of scale is present and replaces it with the "pretty" version of that scale. Maybe instead of automating this, we can point to and provide guidance on using the existing scales package?
@fingertipsy Could we not write a function to be passed to the breaks argument of scale_y_continuous?
Or perhaps we could submit a feature request on the ggplot2 repo?
yes, we could have a function that does something like:
limits_pretty <- function(x, ...) range(pretty(x, ...))
ggplot(data, mapping, ...) + scale_y_continuous(breaks = pretty, limits = limits_pretty)
I could not find a way to pass this down as a default via the existing theme_af() or use_afcharts(). So the only options I could think of were:
Neither seemed like a great idea. 1.) is basically a small subset of what you can do using the scales package. You have to write the extra line of code to set the axis either way. Not sure, it would add much for users to have a function afcharts::pretty_y_axis()? 2.) seemed like a bad idea, because it would very much change the scope of the package.
Happy to discuss at the next meeting
Thanks. I agree, I don't think this is something we should add to the package.
Could you update the cookbook please with an example of how the user can use the following to fix the problem?
limits_pretty <- function(x, ...) range(pretty(x, ...))
ggplot(data, mapping, ...) +
scale_y_continuous(breaks = pretty, limits = limits_pretty)
I'll create an issue on the ggplot2 package and see if this is an issue that could be added.
I think having the top horizontal gridline above the highest data point can make the data easier to read. I'm not sure if this is documented in the AF charts guidance though. Gridlines are easy to set manually when you know what the data values are, but are difficult to automate.