tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.51k stars 2.02k forks source link

Document breaking changes in internal API #3436

Closed cpsievert closed 8 months ago

cpsievert commented 5 years ago

At least a handful of pretty important packages (e.g., plotly, shiny, etc) rely on the data structure returned by ggplot_build()...it'd be really helpful to have a news note when these things change as well as a short statement on why they've changed.

Since the latest CRAN release (3.2.0), I've noticed at least one change, have there been any others?

cpsievert commented 5 years ago

It appears https://github.com/tidyverse/ggplot2/commit/6c2fe76e77a50aae5935935a8d17e404a8100871 introduced another breaking change to [x/y].major (they are now NULL). I'm not sure if that is intentional or not...there are no unit tests on these fields

Before 6c2fe76e77a50aae5935935a8d17e404a8100871:

library(ggplot2)
p <- ggplot(iris) +
  geom_point(aes(x = Petal.Width, y = Sepal.Length, color = Species)) +
   scale_x_continuous(breaks = seq(0,3,0.5), limits =c(0,3), labels = letters[1:7])
b <- ggplot_build(p)
b$layout$panel_params[[1]]$x.major
[1] 0.04545455 0.19696970
[3] 0.34848485 0.50000000
[5] 0.65151515 0.80303030
[7] 0.95454545

After 6c2fe76e77a50aae5935935a8d17e404a8100871:

b$layout$panel_params[[1]]$x.major
NULL
cpsievert commented 5 years ago

Ahhh, it must be x$break_positions() now instead of x.major?

b$layout$panel_params[[1]]$x$break_positions()
[1] 0.04545455 0.19696970
[3] 0.34848485 0.50000000
[5] 0.65151515 0.80303030
[7] 0.95454545
clauswilke commented 5 years ago

I think this is all part of @paleolimbot's refactoring of axes. The end result should be much cleaner and more maintainable, but there's going to be some pain transitioning.

@paleolimbot It might be helpful if you could prepare a brief document explaining the key design choices and showing with simple examples how relevant information about the panels and axes can be extracted under your new system. This might fit into the (as of yet nonexistent) ggplot2 internal development vignette, or alternatively into the vignette on extending ggplot2.

cpsievert commented 5 years ago

but there's going to be some pain transitioning.

This pain could be significantly reduced if there was a "Breaking changes in internal API" section of the news that stated something like:

A vignette might be helpful in this particular case, but generally speaking, when these sort of changes are made, they should be documented in a simple and consistent fashion.

paleolimbot commented 5 years ago

@clauswilke is right, this is my fault! The overarching theme of my internship is formalizing the structure of the panel_params between coordinate systems, and changing how the guides are drawn. We haven't documented the changes yet because they're a few PRs away from done, but there will definitely be a prominent NEWS item and improved documentation for the internal Coord ggproto docs (and at least a blog post).

In the future panel$x and panel$y will be Scale-like objects, and panel$guides will be a list of guide objects (which will hopefully be ggproto in the near future) for the left/right/top/bottom of the panel. In the meantime, we could easily add back in the old syntax to the panel_params and deprecate it more slowly. The panel_params are entirely undocumented (and coord-specific) and I could only find references to x.range and y.range internally, which is why the breaks and labels were removed.

cpsievert commented 5 years ago

Now that I think of it, if possible, it'd be great to have informative warning (instead of NEWS item) if you try to access these deprecated fields.

paleolimbot commented 5 years ago

We could do that if we make panel_params ggproto and make those fields active bindings? I think it would be easier just to add the breaks back into panel_params and phase them out in a future release.

paleolimbot commented 5 years ago

Just a note that now that #3398 is merged, there are a few more changes in the CoordCartesian panel params (I don't think they break compatibility though). Between the previous changes implementing ViewScales and the most recent one (implementing the new axis guides), I think we will wait to see what problems come up, fix them, then document the changes.

teunbrand commented 8 months ago

This release we documented changes to the internals in its own header and I think this is probably something we should keep doing in the future.