Skip to content
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

Colourbar tick and frame linewidths #4314

Closed
teunbrand opened this issue Jan 12, 2021 · 5 comments · Fixed by #4318
Closed

Colourbar tick and frame linewidths #4314

teunbrand opened this issue Jan 12, 2021 · 5 comments · Fixed by #4318
Labels
guides 📏 visual change 👩‍🎨 Rendering change that will affect look of output

Comments

@teunbrand
Copy link
Collaborator

Hello there,

This is just a minor inconsistency, but in case this wasn't noticed yet, here it is. Apparently, guide_colourbar() uses the ticks.linewidth and frame.linewidth parameter as-is, while in the rest of ggplot2 (as far as I can tell), almost every parameter for linewidth is calculated as below:

# Right before handing `supplied_value` to grid
lwd = supplied_value * .pt

Here is a reprex with exaggerated line sizes. You can notice when comparing the width of geom_line() versus the colourbar guide ticks. The lines appear of the same width when you adjust ticks.linewidth = 5 * .pt.

library(ggplot2)

df <- data.frame(x = c(0, 1), y = c(0.5, 0.5))

ggplot(df, aes(x, y)) +
  geom_point(aes(colour = x)) +
  geom_line(size = 5) +
  scale_colour_gradientn(
    colours = c("white", "white"),
    guide = guide_colourbar(ticks.colour = "black", ticks.linewidth = 5)
  )

Created on 2021-01-12 by the reprex package (v0.3.0)

Thanks for reading!

@clauswilke
Copy link
Member

The correct comparison is with theme elements. I believe they don't multiply by .pt, but I could misremember.

@teunbrand
Copy link
Collaborator Author

teunbrand commented Jan 12, 2021

That indeed would be a fairer comparison, though also the theme elements appear to use the * .pt. Seen in the code of element_grob.element_line() here:

ggplot2/R/theme-elements.r

Lines 248 to 256 in 37eb64d

gp <- gpar(
col = colour, fill = colour,
lwd = len0_null(size * .pt), lty = linetype, lineend = lineend
)
element_gp <- gpar(
col = element$colour, fill = element$colour,
lwd = len0_null(element$size * .pt), lty = element$linetype,
lineend = element$lineend
)

@clauswilke
Copy link
Member

Then it probably should do so in the color bar also.

@teunbrand
Copy link
Collaborator Author

teunbrand commented Jan 16, 2021

Thanks so I thought as well. Should I leave a PR for you to consider?

@clauswilke
Copy link
Member

Yes, please go ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guides 📏 visual change 👩‍🎨 Rendering change that will affect look of output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants