Skip to content

Colourbar tick and frame linewidths #4314

Closed

Description

@teunbrand

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!

Activity

  1. clauswilke commented on Jan 12, 2021

    @clauswilke
    Member

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

  2. teunbrand commented on Jan 12, 2021

    @teunbrand
    CollaboratorAuthor

    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
    )

  3. clauswilke commented on Jan 12, 2021

    @clauswilke
    Member

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

  4. teunbrand commented on Jan 16, 2021

    @teunbrand
    CollaboratorAuthor

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

  5. clauswilke commented on Jan 16, 2021

    @clauswilke
    Member

    Yes, please go ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions