JetBrains / lets-plot

Multiplatform plotting library based on the Grammar of Graphics
https://lets-plot.org
MIT License
1.5k stars 47 forks source link

Broken colors with scale_color_discrete and groups #143

Closed IKupriyanov-HORIS closed 3 years ago

IKupriyanov-HORIS commented 4 years ago

image

Python:

mpg_df = pd.read_csv('https://jetbrains.bintray.com/lets-plot/mpg.csv')
ggplot(mpg_df, aes(x='displ', y='hwy')) \
        + geom_point(aes(color='cyl'))\
        + geom_smooth(aes(color='cyl', group='cyl'), method='lm', deg=2, size=1) \
        + scale_color_discrete()

Plot spec for demo:

"""
{
  "data": {
    "Unnamed: 0": [220, 56, 60, 208, 226, 11, 120, 144, 187, 59, 234, 146, 112, 90, 106, 38, 73, 230, 117, 96],
    "manufacturer": ["volkswagen", "dodge", "dodge", "volkswagen", "volkswagen", "audi", "hyundai", "nissan", "toyota", "dodge", "volkswagen", "nissan", "hyundai", "ford", "honda", "dodge", "dodge", "volkswagen", "hyundai", "ford"],
    "model": ["jetta", "dakota pickup 4wd", "durango 4wd", "gti", "new beetle", "a4 quattro", "tiburon", "altima", "camry solara", "durango 4wd", "passat", "altima", "sonata", "f150 pickup 4wd", "civic", "caravan 2wd", "ram 1500 pickup 4wd", "passat", "tiburon", "mustang"],
    "displ": [2.8, 5.2, 4.7, 2.0, 2.5, 2.0, 2.7, 2.5, 2.2, 4.7, 3.6, 3.5, 2.4, 5.4, 1.8, 2.4, 5.7, 2.0, 2.0, 4.6],
    "year": [1999, 1999, 2008, 1999, 2008, 2008, 2008, 2008, 1999, 2008, 2008, 2008, 2008, 2008, 2008, 1999, 2008, 2008, 1999, 1999],
    "cyl": [6, 8, 8, 4, 5, 4, 6, 4, 4, 8, 6, 6, 4, 8, 4, 4, 8, 4, 4, 8],
    "trans": [ "auto(l4)", "manual(m5)", "auto(l5)", "manual(m5)", "manual(m5)", "auto(s6)", "auto(l4)", "auto(av)", "auto(l4)", "auto(l5)", "auto(s6)", "manual(m6)", "manual(m5)", "auto(l4)", "auto(l5)", "auto(l3)", "auto(l5)", "auto(s6)", "manual(m5)", "manual(m5)"],
    "drv": [ "f", "4", "4", "f", "f", "4", "f", "f", "f", "4", "f", "f", "f", "4", "f", "f", "4", "f", "f", "r"],
    "cty": [ 16, 11, 9, 21, 20, 19, 17, 23, 21, 13, 17, 19, 21, 13, 25, 18, 13, 19, 19, 15],
    "hwy": [ 23, 17, 12, 29, 28, 27, 24, 31, 27, 17, 26, 27, 31, 17, 36, 24, 17, 28, 29, 22],
    "fl": [ "r", "r", "e", "r", "r", "p", "r", "r", "r", "r", "p", "p", "r", "r", "r", "r", "r", "p", "r", "r"],
    "class": [ "compact", "pickup", "suv", "compact", "subcompact", "compact", "subcompact", "midsize", "compact", "suv", "midsize", "midsize", "midsize", "pickup", "subcompact", "minivan", "pickup", "midsize", "subcompact", "subcompact"]
  },
  "mapping": {
    "x": "displ",
    "y": "hwy"
  },
  "kind": "plot",
  "scales": [{"aesthetic": "color", "discrete": true}],
  "layers": [
    {
      "geom": "point",
      "mapping": {
        "color": "cyl"
      }
    },
    {
      "geom": "smooth",
      "mapping": {
        "color": "cyl",
        "group": "cyl"
      },
      "method": "lm",
      "deg": 2,
      "size": 1
    }
  ]
}
"""
alshan commented 3 years ago

This was fixed.