-
Notifications
You must be signed in to change notification settings - Fork 2k
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
WIP: Pass actual data to annotation_raster() and annotation_custom() instead of dummy data #3121
WIP: Pass actual data to annotation_raster() and annotation_custom() instead of dummy data #3121
Conversation
in order to support scale transformations
Yes, this is what I mean. Maybe add a regression test that checks for correct behavior under |
Thanks, I'll need to modify the expectations here... ggplot2/tests/testthat/test-annotate.r Lines 33 to 51 in 18be30e
|
I feel
|
Can you add a test for making sure that annotations doesn't affect the scales of the plot? |
Thanks, let me think how to test it... |
@thomasp85 Sorry, I didn't get your point. What do you mean by "annotations doesn't affect the scales of the plot"? I think annotations does affect. library(ggplot2)
library(patchwork)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
p1 <- p + annotate("text", x = 4, y = 25, label = "Some text")
p2 <- p + annotate("text", x = 100, y = 100, label = "Some text")
p1 * p2 Created on 2019-02-19 by the reprex package (v0.2.1.9000) |
Opps, I got it. That's the very reason we needed different annotations than Lines 6 to 10 in 7bafc45
So, by their definitions ("the grob will not be modified by any ggplot settings or mappings"), is this PR invalid? It sounds user's responsibility to provide the correct coordinates. |
I think the intent of the PR is good. annotations should respond to scale transformations, but they should not affect the scales in any way (at least that's my feeling, @hadley can you chime in?) The only way they can respond to transformations is to have the positional data in the actual layer data, so I'm beginning to think that the best way would be to exempt annotation layers from the scale training somehow |
Sure. One possible choice is to transform data in But, it seems I need to wait for #3116 to get some conclusion? |
I don't remember; but if the docs say annotations don't affect the scale limits, then we need to stick with that. My vague recollection is that this makes it possible to add annotations to free scales: e.g. imagining labelling cities on spatial data where each panel has different limits. |
I agree that we should keep the behaviour in line with the documentation, but do you think we should let it respond to scale transformations? (I do) |
Oh yes, definitely. It should respond but not affect. |
Thanks, then I'll keep trying this. I think we have two possible directions:
The latter one is related to the discussion in #3116. Though this is possible with the status quo as this only needs x and y scales, I feel I should wait for the discussion so I can implement this cleaner. |
I agree. The second approach seems cleaner. It would also fit in with another thought I've always had about annotations: You really want to be able to access either the data coordinate system or the plot coordinate system, depending on the context. Sometimes you want to place an annotation at a specific data location. Other times, you want to place it in a specific location on the canvas, e.g. 10% away from the top right corner. The second approach would allow for both, if you transform or not depending on some switch that you add to the annotation geoms. |
Oh, I haven't come up with this, but this is quite true. Thanks. |
Ideally you'd also want to be able to use units in the second scenario. |
Maybe worth considering is making
|
@yutannihilation are you awaiting #3175 for finishing this off? if so, I'll not add it to the 3.2.0 milestone |
Yes, I think I need to wait for it. Sorry I wasn't clear about the current status here. |
No worries... will push this to after the next release |
Any updates, please? The fix doesn't seem to work for me. |
I suspect this might be fixable by using the position scales nested in |
Closing this PR in favour of #6182. |
Fix #3120
This PR does fix these two annotations to have
xmin
,xmax
,ymin
andymax
asdata
so that scale transformations takes effect (this is the same strategy asannotate()
).annotation_raster()
annotation_custom()
On the other hand, this PR doesn't modify
annotation_map()
andannotation_logstick()
because:annotation_map()
: we don't know what to do with the reversed scales for map yet (c.f. scale transformations won't work forcoord_sf()
orcoord_map()
). Besides, annotation itself should not be transformed, but I don't know how to implement this for maps.annotation_logstick()
: the document says "These tick marks probably make sense only for base 10"Created on 2019-02-14 by the reprex package (v0.2.1)