Skip to content

Use of multiple aesthetics in scale_*_manual causes legend to be dropped in ggplotly conversion #2467

@MilesMcBain

Description

@MilesMcBain

Feels related to #2466.

If the {ggplot2} facility to bind a custom scale to muiltiple aesthetics is used, the legend is dropped when the plot is converted plotly.

Reprex:

library(plotly)
library(ggplot2)
library(palmerpenguins)

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

ggplotly(p)
# plot has no legend

Legend appears if we remove references to "fill" and only use "colour".

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