Could colourbar key height and width theme elements be provided?
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 7k
- Forks
- 2.1k
- Avg merge
- 59m
- Merged PRs (30d)
- 2
Description
Currently, you can't always set the legend key height/width as values that will work well as either legend or colourbars - particularly when the legend/colourbar is placed on top. It'd be great, if colourbar.key.height and colourbar.key.width elements could be provided to help here. These elements could inherit from legend.key.*
library(tidyverse)
library(palmerpenguins)
#>
#> Attaching package: 'palmerpenguins'
#> The following objects are masked from 'package:datasets':
#>
#> penguins, penguins_raw
library(patchwork)
set_theme(
theme_grey() +
theme(legend.key.height = rel(1)) +
theme(legend.key.width = rel(0.5)) +
theme(legend.position = "top") +
theme(legend.title.position = "top")
)
p1 <- penguins |>
tidyr::drop_na(sex) |>
ggplot() +
geom_bar(
aes(x = species,
fill = species),
)
p2 <- penguins |>
tidyr::drop_na(sex) |>
ggplot() +
geom_point(
aes(x = flipper_length_mm,
y = body_mass_g,
colour = bill_length_mm),
)
p1 + p2

Created on 2025-08-25 with reprex v2.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the R reprex with the shown ggplot2 themes, comparing the legend and colourbar when positioned at the top. Determine how separate colourbar key height and width elements should inherit from legend.key.*; done means those elements independently produce suitable colourbar dimensions without changing legend sizing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100