Skip to content

Breaks and labels in scale_color_identity don't match. #735

@bmorledge-hampton19

Description

@bmorledge-hampton19

The order of the breaks and labels parameters for scale_color_identity are not being matched properly. Here is a reproducible example:

import pandas
from plotnine import *

df = pandas.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7],
                       'y': [18, 22, 19, 14, 14, 11, 20],
                       "color": ["blue", "red", "blue", "blue", "red", "red", "blue"]})

(
    ggplot(df, aes(x = 'x', y = 'y', color = "color")) + geom_point() +
    scale_color_identity(breaks = ("red", "blue"), labels = ("Red", "Blue"),
                         guide = "legend", name = "")
)

This code produces the following plot with mismatched labels in the legend.
output

It looks like a similar issue was addressed in the past (#445), but the issue still persists here.

On a side note, why does the legend use a default title when an empty string is passed as the name? This seems like strange behavior to me and isn't clearly documented. (The documentation states: "Name used as the label of the scale. This is what shows up as the axis label or legend title. Suitable defaults are chosen depending on the type of scale.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions