-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable more styling options for guide_colorbar(). #2541
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
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.
Some minor style stuff, and a question about the argument names, but otherwise good to go.
NEWS.md
Outdated
@@ -285,6 +285,11 @@ up correct aspect ratio, and draws a graticule. | |||
|
|||
* Default themes use `rel()` to set line widths (@baptiste). | |||
|
|||
### Guides | |||
|
|||
* Make `guide_colorbar()` more configurable; enable styling of tick marks and |
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.
Can you mention the argument names here please?
# frame | ||
frame.colour = NULL, | ||
frame.linewidth = 0.5, | ||
frame.linetype = 1, |
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.
Have we used linewidth
and linetype
in other functions?
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.
linetype
is a standard aesthetic, so I think that's fine. linewidth
is usually called size
throughout the rest of ggplot2. If you prefer size
I'm happy to make the change, it's just that frame.size
doesn't sound like it controls the thickness of the frame.
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 don't have any particularly strong feelings here; I don't really understand how these options are supposed to fit in with the theme system.
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.
Not sure. The question is whether every possible option to a guide function needs a theme equivalent. My personal opinion is no. I think there is a lot of room for improvement for making guide functions more flexible, and possibly providing different ones or frameworks for extending them, and it's impossible to add new theme components every time somebody makes some minor tweak to some guide function. Already, there are things the guide functions can do that the theme can't control, such as the draw.ulim
option for guide_colorbar()
.
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.
Agreed. I'm happy to merge this PR; I just wanted to make sure we at least talked over the issues.
R/guide-colorbar.r
Outdated
|
||
# make frame around color bar if requested (colour is not NULL) | ||
if (!is.null(guide$frame.colour)) { | ||
grob.bar <- grobTree(grob.bar, |
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 you mind adhering to modern tidyverse style here?
grobTree(
grob.bar,
rectGrob(
width = barwidth.c, height = barheight.c, default.units = "mm",
gp = gpar(
col = guide$frame.colour,
lwd = guide$frame.linewidth,
lty = guide$frame.linetype,
fill = NA
)
)
)
or similar
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.
Sure, will do.
R/guide-colorbar.r
Outdated
@@ -352,7 +384,9 @@ guide_gengrob.colorbar <- function(guide, theme) { | |||
y1 = rep(tic_pos.c, 2) | |||
}) | |||
segmentsGrob(x0 = x0, y0 = y0, x1 = x1, y1 = y1, | |||
default.units = "mm", gp = gpar(col = "white", lwd = 0.5, lineend = "butt")) | |||
default.units = "mm", gp = gpar(col = guide$ticks.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.
And here
Just a note: I'll wait with finalizing this PR until after #2415 is integrated, since they touch the same files. |
I believe this latest update addresses all concerns. I added two minimal visual tests, one for the default styling (it also tests that colors can be changed via scale_color_..., so is useful anyways I think) and one for the modified styling of both the frame and the tick lines. |
Thank you! |
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/ |
Inspired by StackOverflow questions here and here: This patch enables better styling of the colorbar guide.
Examples:
This pull request will require some modifications once #2415 is integrated (or vice versa). I'm happy to take care of that.