Skip to content

Feature request: enable expand arguments for continuous color and fill scales. #3508

Closed
@atusy

Description

@atusy

Unlike scales for continuous x or y (e.g., scale_x_continuous), those for color or fill (e.g., scale_color_gradient) is not supporting expand option.
At least, I want expand = c(0, 0) to work so that color bars exactly represents the range of color or fill mappings.

The example below shows that range of color bar is wider than the range specified in limits argument even if expand = c(0, 0) is specified.

@yutannihilation figured out this is caused by

tick_pos <- rescale(guide$key$.value, c(0.5, guide$nbin - 0.5), guide$bar$value[c(1, nrow(guide$bar))]) * barlength / guide$nbin

x <- c(0, 1)
ggplot2::qplot(x, x, color = x) + 
  ggplot2::scale_color_gradient(breaks = x, limits = x, expand = c(0, 0)) +
  ggplot2::guides( # Just for the visibility
    color = ggplot2::guide_colorbar(
      barheight = grid::unit(1, "npc") - grid::unit(4, "line"),
      ticks.linewidth = 2
    )
  )

Created on 2019-08-29 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions