tidyverse / tidyverse/ggplot2

default_aes not used in compute_*() methods

Open
#3,860 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

internals :mag_right:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

While writing about extensions I noticed that the content of default_aes in a stat is not added to the data before it is passed through the compute_*() mill. This effectively renders it useless for anything but defining mappings for the geom.

The current code reflects this as it has all sorts of code around extracting non-required aesthetics from the data, e.g. in StatBinHex

https://github.com/tidyverse/ggplot2/blob/1223de2d6841be4276b5b398aff747672797c1b9/R/stat-binhex.r#L45-L65

we set a default weight, but still has to guard it with data$weight %||% rep(1L, nrow(data)) when using it in compute_group()

I cannot see any meaningful reason why this is so, and the fix seems obvious. Have I missed an underlying reason @hadley?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with R/stat-binhex.r, especially the default weight handling around the linked lines, and trace how default_aes data reaches compute_*() methods. Compare the current StatBinHex behavior with other Stat implementations and existing tests; done means defaults are available during computation without breaking aesthetic mappings or required-aesthetic handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.