group Aesthetic¶Default Grouping Behavior:
color, shape, linetype, etc.lines, paths, polygons) for each unique combination of these variablesExplicit Group Control:
group = 'var' to group only by that specific variable, overriding default groupinggroup = [var1, var2, ...] to group by the interaction of multiple variablesgroup = [] to disable all grouping completelyfrom lets_plot import *
import polars as pl
LetsPlot.setup_html()
mtcars = pl.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/refs/heads/master/data/mpg.csv")
mtcars.head()
seed = 21
( ggplot(mtcars, aes(x='drv', y='hwy'))
+ geom_violin(tooltips='none')
+ geom_sina(seed=seed)
)
color¶( ggplot(mtcars, aes(x='drv', y='hwy'))
+ geom_violin(tooltips='none')
+ geom_sina(aes(color='cyl'), seed=seed)
)
color: Default Grouping Creates Unwanted Separation¶Let's add discrete colors by marking the cyl variable as discrete.
When we map color=as_discrete('cyl'), Lets-Plot automatically groups the data by the discrete color variable. \
This means:
drv (x-axis) and cyl (color) becomes a separate groupgeom_sina() uses "dodge" positioning by default, which separates overlapping groups horizontally( ggplot(mtcars, aes(x='drv', y='hwy'))
+ geom_violin(tooltips='none')
+ geom_sina(aes(color=as_discrete('cyl')), seed=seed)
)
( ggplot(mtcars, aes(x='drv', y='hwy'))
+ geom_violin(tooltips='none')
+ geom_sina(aes(color=as_discrete('cyl'),
group='drv' # <-- group only by drive type (ignoring the color variable for grouping)
), seed=seed)
)
( ggplot(mtcars, aes(x='drv', y='hwy'))
+ geom_violin(tooltips='none')
+ geom_sina(aes(color=as_discrete('cyl'),
group=[] # <-- disable all grouping entirely
), seed=seed)
)