{ "cells": [ { "cell_type": "markdown", "id": "f40905f8-002a-4e51-97b2-a527a2a5af05", "metadata": {}, "source": [ "# Overriding Default Grouping with the `group` Aesthetic\n", "\n", "#### How Grouping Works in Lets-Plot\n", "\n", "Default Grouping Behavior:\n", "- Lets-Plot automatically groups data by discrete variables mapped to aesthetics like `color, shape, linetype`, etc.\n", "- This creates separate visual elements (`lines, paths, polygons`) for each unique combination of these variables\n", "\n", "Explicit Group Control:\n", "- Use `group = 'var'` to group only by that specific variable, overriding default grouping\n", "- Use `group = [var1, var2, ...]` to group by the interaction of multiple variables\n", "- Use `group = []` to disable all grouping completely\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "5949c620-ad0a-40c6-94dd-fe607f460c2e", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *\n", "import polars as pl" ] }, { "cell_type": "code", "execution_count": 2, "id": "fabe8230-fc90-427c-afd9-6dd9f22c7a96", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "436e50eb-0f1a-46d1-90b5-804d1793cb04", "metadata": {}, "outputs": [ { "data": { "text/html": [ "| manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| i64 | str | str | f64 | i64 | i64 | str | str | i64 | i64 | str | str |
| 1 | "audi" | "a4" | 1.8 | 1999 | 4 | "auto(l5)" | "f" | 18 | 29 | "p" | "compact" |
| 2 | "audi" | "a4" | 1.8 | 1999 | 4 | "manual(m5)" | "f" | 21 | 29 | "p" | "compact" |
| 3 | "audi" | "a4" | 2.0 | 2008 | 4 | "manual(m6)" | "f" | 20 | 31 | "p" | "compact" |
| 4 | "audi" | "a4" | 2.0 | 2008 | 4 | "auto(av)" | "f" | 21 | 30 | "p" | "compact" |
| 5 | "audi" | "a4" | 2.8 | 1999 | 6 | "auto(l5)" | "f" | 16 | 26 | "p" | "compact" |