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

ViewScale's break_positions() now returns pre-transformed positions #5029

Closed
cpsievert opened this issue Nov 3, 2022 · 3 comments
Closed

Comments

@cpsievert
Copy link
Contributor

Consider the following plot

# Create some noisy exponentially-distributed data
dat <- data.frame(
  xval = c(0.26932812,-0.05341404,0.36977717,0.91504712,0.46329006,0.37956526, 0.93290644,0.75558976,0.67633497,0.48655293,0.79478162,0.55109982, 0.51681398,0.81073512,0.49406579,0.93919618,0.90472008,0.98732256, 0.94379876,0.95790909,0.54614241,1.13356941,1.13299144,1.18159277, 1.16428407,1.22955005,1.21030897,1.23314811,1.53822718,1.53674330, 1.80020468,1.40774011,1.74573515,1.26651625,2.06607711,1.50237263, 1.38480531,1.83625381,2.35275649,1.99004291,2.80396442,2.20863240, 2.42998876,2.12801180,2.26290348,2.38185989,2.14936036,2.66587947, 2.64586596,2.44240603,2.39266452,3.11831215,2.70258927,2.65529134, 2.65634690,2.95984290,2.71058076,2.87919480,3.07739358,2.66841935, 3.10792706,3.17134285,3.98070271,3.55497279,3.36831009,3.31390892, 3.32753965,2.86981968,3.22741000,3.78806438,3.74434536,3.56928928, 3.83783177,3.24485807,4.05766233,4.13619455,4.26888054,3.47546258, 3.93045819,3.77620080,4.66676431,3.88059240,4.54694485,4.03915767, 4.25556093,4.39251819,4.42692029,4.23262929,4.44890758,4.84981161, 4.51104252,4.33004508,5.06350705,4.89714069,4.21599077,4.55457578, 5.04044393,4.89111297,5.03105215,4.64113164), 
  yval = c(1.177512e+01,7.303113e+00,6.109053e+00,2.545169e+01,3.366341e+01,1.042255e+01,2.703767e+01,1.178223e+01,4.495965e+01,1.614609e+01,4.003015e+01,1.038442e+02,4.024992e+01,4.163942e+01,9.108197e+01,3.116299e+01,2.558871e+02,7.482977e+01,2.502789e+01,5.923683e+01,3.967814e+01,9.207318e+01,1.298618e+02,1.138197e+02,1.804303e+02,3.363494e+02,3.197204e+02,4.968737e+02,1.783433e+02,4.765546e+02,4.486885e+02,6.736079e+02,4.289288e+02,3.433946e+02,5.658634e+02,4.667053e+02,5.257803e+02,3.401038e+02,6.131335e+02,5.928647e+02,7.838524e+02,7.987915e+02,3.348470e+03,1.704767e+03,1.264169e+03,2.690011e+03,2.738240e+03,1.663862e+03,5.377442e+03,3.883820e+03,6.673624e+03,1.857346e+03,6.683962e+03,1.213027e+03,1.742885e+03,2.146094e+03,4.597174e+03,4.357154e+03,8.413851e+03,8.194194e+03,7.076611e+03,1.554628e+04,6.984783e+03,1.027392e+04,1.158795e+04,9.193111e+03,3.226748e+04,3.955445e+04,2.978953e+04,1.926420e+04,7.610544e+04,2.129694e+04,1.438764e+04,7.908876e+04,2.676003e+04,1.791758e+05,3.978871e+04,9.411120e+04,4.486940e+04,1.270526e+05,1.587331e+05,1.616173e+05,3.351522e+05,3.001782e+05,2.527824e+05,2.745851e+05,3.446376e+05,1.544497e+05,1.318314e+05,8.334336e+05,2.464391e+05,8.694818e+05,2.747323e+05,6.373497e+05,2.918690e+05,9.505114e+05,7.835278e+05,3.775567e+05,1.795523e+06,1.568159e+06)
)

p <- ggplot(dat, aes(xval, yval)) +
  geom_point() + 
  coord_trans(y = "log2")

image

If I build it and look at the $break_positions() of the y-axis, they don't seem to consider the coordinate transformation (prior to 3.4.0, they did):

b <- ggplot_build(p)
b$layout$panel_params[[1]]$y$break_positions()
#> [1]        NA 0.2967544 0.5935098 0.8902652

Thankfully, the y.range field has the post-transformed values. However, it'd be nice if break_positions() yielded the same result, especially considering that y.major was silently dropped in recent releases(#3436)

b$layout$panel_params[[1]]$y.major
#> [1] 0.9122862 0.9623324 0.9916076
@cpsievert
Copy link
Contributor Author

Perhaps part of the problem is that panel_params has lost it's transformation along the way somehow?

p$coordinates$trans$y
#> Transformer: log-2 [1e-100, Inf]

b$layout$panel_params[[1]]$y$scale$trans
#> Transformer: identity [-Inf, Inf]

cpsievert added a commit to plotly/plotly.R that referenced this issue Nov 4, 2022
* Close #2193: Accomodate breaking changes in ggplot2 3.4.0

* Line-based theme elements now also use linewidth over size

* Support GeomBoxplot linewidth as well

* Support GeomPolygon linewidth as well

* Support GeomBar linewidth as well

* Handle more linewidth theme changes

* Use both linewidth and size for sf

* geom_area() now has a different default for stat

* Approve differences due to changes in legend order

* Convert borderwidth correctly on colorbar

* Refactor/consolidate core logic

* Approve new sf baseline

* Fix sf issue

* Approve new sf baseline

* break_positions() no longer contains post-transformed values

tidyverse/ggplot2#5029

* Add comment; prefer dimension() of the scale over .range
@yutannihilation
Copy link
Member

Since this is about coord_trans() and ViewScale, #3972 might be the cause. If I understand correctly, before v3.4.0, CoordTrans had Scale objects, not ViewScale ones. There should be no change on ViewScale's break_positions().

I'm not immediately sure if my guess is right or wrong, and what's the supposed behavior here. Let me think...

@teunbrand
Copy link
Collaborator

The preferred interface for accessing key values in guides is through get_guide_data(), so that (hopefully) accessing the internals to extract tick mark locations won't be needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants