-
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
More aesthetics for geom_label()
#5454
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, Steve!
I like the intent of the PR and the comments I've made are mostly about polishing and conventions. I don't think ggplot2 has settled on how paired aesthetics (colour
/border_colour
) should be implemented yet, but I can bring it up with Thomas soon.
R/geom-label.R
Outdated
border_colour = NULL, | ||
border_color = border_colour) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add these to the formals of geom_label()
as well? It might also be best to standardise to UK spelling immediately in geom_label()
. In addition, I think ggplot2 has settled at using dot.case instead of snake_case for most arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in 3002125
As for dot.case vs. snake_case, it's not consistent, so I'm not sure. nudge_x
and nudge_y
are arguments that use snake_case in that same function. And the function name itself is geom_label
. I'll lean towards underscore unless it's clearly settled. If so, happy to change it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument names should use dot.case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you can think up a name that doesn't have variation between UK/US spelling it would be preferable because we really have gripes with the decision to support both. While we can't backtrack on that decision we can attempt to limit new entrants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I updated to dot.case.
-
Yeah, I see how the redundant variables are a headache. I couldn't come up with a good alternative to term for colour/color, so I'm copying what the rest of ggplot does. Open to alternatives!
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
I've updated the comment at the beginning. See the two remaining questions. |
I was looking for that exactly! Thank you very much. I guess that before this PR, it was not possible to only apply the color to the label box? After this PR, some work will be required in ggrepel to make geom_label_repel() understand that? |
The ggrepel package has always been free to do whatever it wants with labels, so there'd be no need to wait on this PR for that.
I have to probe Thomas' wisdom on some points, I'll get back on this on tuesday/wednesday. As a quick comment though: I don't think you'd need all the examples to show all the aesthetics. Most people should be familiar with what 'linewidth' is doing and how this might apply to textboxes. The |
@teunbrand Thanks. Fair point about the examples. How about these three? The last could be simpler, but I think it's a use case some people may want to copy. p = ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars)))
# If border.colour is NULL or not set, the border will use the text color
p + geom_label(aes(color = factor(cyl))) # Alternatively, border.colour can have a static value
p + geom_label(aes(color = factor(cyl)), border.colour = "black") # Use linetype and linewidth aesthetics to add highlights
p + geom_label(
aes(fill = factor(cyl), linetype = qsec < 15),
border.colour = "black", color = "white", linewidth = 1) +
scale_linetype_manual(values=c("solid", "blank"), limits = TRUE, labels = "1/4 mi < 15s", name = NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Steve,
I had a chat with Thomas and we agree that PR's direction is great.
I've left some minor formatting comments.
About the legend clipping, I think legends should be slightly smarter about determining the size of the keys, so I'll try to fix that in a seperate PR first before we can merge this one.
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Co-authored-by: Teun van den Brand <49372158+teunbrand@users.noreply.github.com>
Thanks @teunbrand! |
If #5465 gets merged, we can fix the key glyph cropping issue. |
I'm moving this PR back to a draft to consider to make |
Yeah that is exactly what Thomas and I were discussing, but we both thought making
The mechanism already has precedence in |
Personally, I find fixed parameters extremely frustrating because very quickly collaborators or audiences for plots that use them start to ask for data-dependent customization of them (eg, making the linetype for the whiskers match the linetype for the box or vary depending on whether they cross a threshold). It would seem that a better solution in the case of #5423 would be to add the |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
Is there any chance this will be merged for this release? or will this get looked at after release? |
@olivroy This PR is currently set as a draft (so we cannot merge it) and the release process has been kicked off. |
Been busy with other things. But I'll try to work on it this weekend. |
There is no rush, I'm reasonably sure that the upcoming release would have to be patched afterwards so we can include it in that release. If someone needs these features right this instant, they can extend |
Hi @steveharoz, are you still interested in finishing this PR? If you're busy with other things that is fine too, and we'd be happy to take over from here. |
Updates to
geom_label()
's aesthetics and parametersgeom_label()
now have the same rounded rectangle shape and aesthetics as the labels. (See questions below)Old: New:
Deprecated
label.size
. Uselinewidth
instead, which is more consistent with the rest of ggplot.IfUpdate: setting up a soft deprecation fallback was too messy when going from an argument to an aesthetic, so I fully deprecatedlinewidth
is not set, it'll fall back tolabel.size
, so nothing should break.label.size
.New aesthetic:
linetype
for the label border. Default: "solid". Addressesgeom_label
doesn't allow for varying line types #5365New parameter:
border_colour
is the color of the label's border and is decoupled from the text color. If the value isNULL
or not set, it will fall back to the text color, which is how it worked previously. Hopefully, that will avoid any breaking changes.I added three examples to the docs. The mtcars graphs are too crowded to show off all the new aesthetics, so I made a dummy dataset for the latter two:
Questions:
Does the deprecated messaging look right for label.size?Are the aliases border_colour/border_color dealt with appropriately?