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
Double coordinate transformations for geoms that draw with other geoms #2149
Comments
I don't see any obvious way to fix this. It'll have to wait until someone is deeper into coordinate systems. |
I think the correct way to fix this is to copy the line-drawing code from Lines 106 to 141 in 4d2ca99
and modify appropriately for geom_abline() etc. It's the geom's responsibility to draw correctly given the data and the coord, and if a geom can't guarantee correct drawing when using another geom's drawing code then it needs to provide its own.
|
I'd be happy to try to put together a PR. There's one important question, though: Is the intent that lines are straight in the data coordinate system, so they may become curved in the transformed space, or should they always be straight in the final plot? |
I think they have to be straight in the data coordinate system, otherwise I can’t imagine how you’d interpret the parameters in (eg) polar coordinates. |
Actually, I was too quick in blaming Lines 14 to 35 in 8778b48
Thus, I can trigger a similar problem with library(ggplot2)
df <- data.frame(x = c(-Inf, Inf), y = c(1, 2))
p <- ggplot(df, aes(x, y)) + geom_line() + xlim(1, 2)
p p + coord_flip() p + coord_polar() p + coord_trans(y = "log10") p + coord_trans(x = "log10")
#> Warning in self$trans$x$transform(x): NaNs produced
#> Warning in trans$transform(value): NaNs produced
#> Warning: Transformation introduced infinite values in x-axis Created on 2018-08-09 by the reprex package (v0.2.0). Notice how |
* rename range() function of coord to backtransform_range() * update news. closes #2149, #2812 * add range backtransformation function. closes #2820. * fix typo in coord code * add backtransform_range() to coord_map * update summarise_layout to use backtransform_range() instead of range(). * Update coord documentation * undo API cleanup * update documentation * rebase * fix remaining issue from rebase
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
When a
geom
queries the coordinate range and uses the result to create data that is then plotted by anothergeom
, there is potentially a double transformation. i.e.coord.range()
yields results in coordinate space and if followed bycoord.transform()
, the data may get transformed two times. Affectscoords
that transform the limits incoord$setup_panel_params
and also do transforms incoord$transform
. This includescoord_trans
andcoord_sf
.Affected geoms include
geom_abline
,geom_hline
andgeom_hline
.reprex
The red line (at x=3) should be top to bottom.
The text was updated successfully, but these errors were encountered: