Skip to content

Unused aesthetic in scale_*_manual causes ggplotly conversion to fail #2466

@MilesMcBain

Description

@MilesMcBain

If you create a manual colour scale mapping for an aesthetic that isn't used {ggplot2} doesn't care, but {plotly} cannot successfully convert the plot.

This might show up if you try to create an organisational colour scale theme you want the user to use as a one liner, without care for the underlying aesthetics in play (works well with native ggplot2).

Reprex:

library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(ggplot2)
library(palmerpenguins)

p <-
  penguins |>
  ggplot(aes(
    x = body_mass_g,
    y = bill_length_mm,
    colour = species
  )) +
  geom_point() +
  scale_colour_manual(
    values = c(
        "Adelie" = "red",
        "Chinstrap" = "green",
        "Gentoo" = "blue"
    ),
    aesthetics = c("colour", "fill")
  )

  ggplotly(p)
#> Error in `[.data.frame`:
#> ! undefined columns selected

Created on 2026-01-09 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions