Add I() for literal values and panel-relative positions - #1124
Merged
Merged
Conversation
Let I() mark an aesthetic value as literal. Literal values bypass scale training, mapping, and legends while retaining their ordinary numeric or discrete classification. Store the tag in the pandas dtype so dataframe operations preserve it. Treat bare I() calls as literal expressions, while derived expressions remain ordinary mappings and retain their labels. Skip tagged columns during scale and guide processing so layers can combine literal and mapped values for the same aesthetic.
Allow annotate() positions wrapped in I() to bypass position scales and resolve as panel fractions. Repeat a length-one position to match the other position vectors, including under faceting.
Resolve positions wrapped in I() against each panel after scales and coordinate parameters are ready. Convert the resulting fractions to data coordinates, including transformed-space behaviour and coord_flip handling.
Measure panel fractions in the drawn coordinate space, then invert the result before writing it to the data column. Literal positions now appear at the visual centre under transformed coordinates.
Document I() in the API reference and describe literal values and panel-relative annotation positions in the changelog.
Add baseline images for literal colours, panel-relative annotations, and coord_flip rendering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
I(), which marks an aesthetic value as literal.Until now every aesthetic value went through a scale, so there was no way to hand a layer values to be used exactly as written. To put a label at 90% of the y axis you had to partly build the plot to compute what the limits would be, and work out the data coordinate yourself. Even with a helper function, it was still clanky.
Before
Now
( ggplot(mpg, aes("displ", "hwy")) + geom_point() + annotate("text", x=3, y=I(0.9), label="90%", color="red") )closes #1008
closes #939