Skip to content

Change in aesthetic column order in get_layer_data() output in ggplot2 v4.0.0 #6614

@thomas-arocena

Description

@thomas-arocena

Hello ggplot2 team,

First, thanks for the work on the 4.0.0 release and the S7 migration!

I’m seeing a change in the ordering of columns returned by get_layer_data() depending on whether aesthetics are specified in a single aes() call or split across multiple aes() calls.

library(ggplot2)

# Case 1: all aesthetics in one aes()
p1 <- ggplot(penguins) +
  aes(x = bill_dep, y = bill_len, colour = species, shape = island) +
  geom_point()

# Case 2: aesthetics split across two aes() calls
p2 <- ggplot(penguins) +
  aes(x = bill_dep, y = bill_len) +
  aes(colour = species, shape = island) +
  geom_point()

ld1 <- get_layer_data(p1)
ld2 <- get_layer_data(p2)

print(names(ld1)[1:4])
print(names(ld2)[1:4])

On ggplot2 v4.0.0, I observe:

[1] "x"      "y"      "colour" "shape" 
[1] "colour" "shape"  "x"      "y"  

So when aesthetics are added across multiple aes() calls, the merged mapping appears to reorder the columns in the layer data (non-positional aesthetics like colour/shape come before x/y).

Questions

  • Is this reordering intentional in v4.0.0 (e.g., due to internal changes with S7/merging of mappings), or an unintended side effect?
  • For downstream code/packages that inspect get_layer_data(), should we avoid assuming any column order and always access columns by name?
  • If the change is unintentional, is there a plan to restore the previous ordering in a patch release—or should we consider the new ordering as the correct behavior going forward?

Thanks a lot for your guidance and for all your work on ggplot2!

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