source/kotlin_examples/cookbook/ggrepel.ipynb (8,735 lines of code) (raw):
{
"cells": [
{
"cell_type": "markdown",
"id": "fed6d06a-c5a6-49cd-949c-7d4c9ed9b8a1",
"metadata": {},
"source": [
"# Dynamic Text Positioning with Repel Geometries\n",
"\n",
"- `geomTextRepel()`\n",
"- `geomLabelRepel()`\n",
"\n",
"These functions use a force-based layout algorithm to automatically reposition text labels and resolve overlaps.\n",
"\n",
"Labels repel each other and their associated data points while staying within the plot boundaries."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "bd28eb0e-f782-4b58-a250-c2dde64c16e4",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:04:59.793469Z",
"iopub.status.busy": "2025-12-03T16:04:59.791944Z",
"iopub.status.idle": "2025-12-03T16:05:02.496282Z",
"shell.execute_reply": "2025-12-03T16:05:02.496007Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"kotlin_out_0\"></div>\n",
" <script type=\"text/javascript\">\n",
" if(!window.kotlinQueues) {\n",
" window.kotlinQueues = {};\n",
" }\n",
" if(!window.kotlinQueues[\"DataFrame\"]) {\n",
" var resQueue = [];\n",
" window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
" window[\"call_DataFrame\"] = function(f) {\n",
" resQueue.push(f);\n",
" }\n",
" }\n",
" (function (){\n",
" var modifiers = [(function(script) {\n",
" script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@3db46ccccaa1291c0627307d64133317f545e6ae/core/src/main/resources/init.js\"\n",
" script.type = \"text/javascript\";\n",
"})];\n",
" var e = document.getElementById(\"kotlin_out_0\");\n",
" modifiers.forEach(function (gen) {\n",
" var script = document.createElement(\"script\");\n",
" gen(script)\n",
" script.addEventListener(\"load\", function() {\n",
" window[\"call_DataFrame\"] = function(f) {f();};\n",
" window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
" window.kotlinQueues[\"DataFrame\"] = [];\n",
" }, false);\n",
" script.addEventListener(\"error\", function() {\n",
" window[\"call_DataFrame\"] = function(f) {};\n",
" window.kotlinQueues[\"DataFrame\"] = [];\n",
" var div = document.createElement(\"div\");\n",
" div.style.color = 'darkred';\n",
" div.textContent = 'Error loading resource DataFrame';\n",
" document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
" }, false);\n",
" \n",
" e.appendChild(script);\n",
" });\n",
" })();\n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" <style>\n",
" :root {\n",
" --background: #fff;\n",
" --background-odd: #f5f5f5;\n",
" --background-hover: #d9edfd;\n",
" --header-text-color: #474747;\n",
" --text-color: #848484;\n",
" --text-color-dark: #000;\n",
" --text-color-medium: #737373;\n",
" --text-color-pale: #b3b3b3;\n",
" --inner-border-color: #aaa;\n",
" --bold-border-color: #000;\n",
" --link-color: #296eaa;\n",
" --link-color-pale: #296eaa;\n",
" --link-hover: #1a466c;\n",
"}\n",
"\n",
":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
" --background: #303030;\n",
" --background-odd: #3c3c3c;\n",
" --background-hover: #464646;\n",
" --header-text-color: #dddddd;\n",
" --text-color: #b3b3b3;\n",
" --text-color-dark: #dddddd;\n",
" --text-color-medium: #b2b2b2;\n",
" --text-color-pale: #737373;\n",
" --inner-border-color: #707070;\n",
" --bold-border-color: #777777;\n",
" --link-color: #008dc0;\n",
" --link-color-pale: #97e1fb;\n",
" --link-hover: #00688e;\n",
"}\n",
"\n",
"p.dataframe_description {\n",
" color: var(--text-color-dark);\n",
"}\n",
"\n",
"table.dataframe {\n",
" font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
" font-size: 12px;\n",
" background-color: var(--background);\n",
" color: var(--text-color-dark);\n",
" border: none;\n",
" border-collapse: collapse;\n",
"}\n",
"\n",
"table.dataframe th, td {\n",
" padding: 6px;\n",
" border: 1px solid transparent;\n",
" text-align: left;\n",
"}\n",
"\n",
"table.dataframe th {\n",
" background-color: var(--background);\n",
" color: var(--header-text-color);\n",
"}\n",
"\n",
"table.dataframe td {\n",
" vertical-align: top;\n",
" white-space: nowrap;\n",
"}\n",
"\n",
"table.dataframe th.bottomBorder {\n",
" border-bottom-color: var(--bold-border-color);\n",
"}\n",
"\n",
"table.dataframe tbody > tr:nth-child(odd) {\n",
" background: var(--background-odd);\n",
"}\n",
"\n",
"table.dataframe tbody > tr:nth-child(even) {\n",
" background: var(--background);\n",
"}\n",
"\n",
"table.dataframe tbody > tr:hover {\n",
" background: var(--background-hover);\n",
"}\n",
"\n",
"table.dataframe a {\n",
" cursor: pointer;\n",
" color: var(--link-color);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"table.dataframe tr:hover > td a {\n",
" color: var(--link-color-pale);\n",
"}\n",
"\n",
"table.dataframe a:hover {\n",
" color: var(--link-hover);\n",
" text-decoration: underline;\n",
"}\n",
"\n",
"table.dataframe img {\n",
" max-width: fit-content;\n",
"}\n",
"\n",
"table.dataframe th.complex {\n",
" background-color: var(--background);\n",
" border: 1px solid var(--background);\n",
"}\n",
"\n",
"table.dataframe .leftBorder {\n",
" border-left-color: var(--inner-border-color);\n",
"}\n",
"\n",
"table.dataframe .rightBorder {\n",
" border-right-color: var(--inner-border-color);\n",
"}\n",
"\n",
"table.dataframe .rightAlign {\n",
" text-align: right;\n",
"}\n",
"\n",
"table.dataframe .expanderSvg {\n",
" width: 8px;\n",
" height: 8px;\n",
" margin-right: 3px;\n",
"}\n",
"\n",
"table.dataframe .expander {\n",
" display: flex;\n",
" align-items: center;\n",
"}\n",
"\n",
"/* formatting */\n",
"\n",
"table.dataframe .null {\n",
" color: var(--text-color-pale);\n",
"}\n",
"\n",
"table.dataframe .structural {\n",
" color: var(--text-color-medium);\n",
" font-weight: bold;\n",
"}\n",
"\n",
"table.dataframe .dataFrameCaption {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"table.dataframe .numbers {\n",
" color: var(--text-color-dark);\n",
"}\n",
"\n",
"table.dataframe td:hover .formatted .structural, .null {\n",
" color: var(--text-color-dark);\n",
"}\n",
"\n",
"table.dataframe tr:hover .formatted .structural, .null {\n",
" color: var(--text-color-dark);\n",
"}\n",
"\n",
"\n",
" </style>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" <div id=\"inZTLK\"></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
" if(!window.letsPlotCallQueue) {\n",
" window.letsPlotCallQueue = [];\n",
" }; \n",
" window.letsPlotCall = function(f) {\n",
" window.letsPlotCallQueue.push(f);\n",
" };\n",
" (function() {\n",
" var script = document.createElement(\"script\");\n",
" script.type = \"text/javascript\";\n",
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.8.1/js-package/distr/lets-plot.min.js\";\n",
" script.onload = function() {\n",
" window.letsPlotCall = function(f) {f();};\n",
" window.letsPlotCallQueue.forEach(function(f) {f();});\n",
" window.letsPlotCallQueue = [];\n",
" \n",
" \n",
" };\n",
" script.onerror = function(event) {\n",
" window.letsPlotCall = function(f) {};\n",
" window.letsPlotCallQueue = [];\n",
" var div = document.createElement(\"div\");\n",
" div.style.color = 'darkred';\n",
" div.textContent = 'Error loading Lets-Plot JS';\n",
" document.getElementById(\"inZTLK\").appendChild(div);\n",
" };\n",
" var e = document.getElementById(\"inZTLK\");\n",
" e.appendChild(script);\n",
" })();\n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" <div id=\"kotlin_out_1\"></div>\n",
" <script type=\"text/javascript\">\n",
" if(!window.kotlinQueues) {\n",
" window.kotlinQueues = {};\n",
" }\n",
" if(!window.kotlinQueues[\"letsPlotJs\"]) {\n",
" var resQueue = [];\n",
" window.kotlinQueues[\"letsPlotJs\"] = resQueue;\n",
" window[\"call_letsPlotJs\"] = function(f) {\n",
" resQueue.push(f);\n",
" }\n",
" }\n",
" (function (){\n",
" var modifiers = [(function(script) {\n",
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.8.1/js-package/distr/lets-plot.min.js\"\n",
" script.type = \"text/javascript\";\n",
"})];\n",
" var e = document.getElementById(\"kotlin_out_1\");\n",
" modifiers.forEach(function (gen) {\n",
" var script = document.createElement(\"script\");\n",
" gen(script)\n",
" script.addEventListener(\"load\", function() {\n",
" window[\"call_letsPlotJs\"] = function(f) {f();};\n",
" window.kotlinQueues[\"letsPlotJs\"].forEach(function(f) {f();});\n",
" window.kotlinQueues[\"letsPlotJs\"] = [];\n",
" }, false);\n",
" script.addEventListener(\"error\", function() {\n",
" window[\"call_letsPlotJs\"] = function(f) {};\n",
" window.kotlinQueues[\"letsPlotJs\"] = [];\n",
" var div = document.createElement(\"div\");\n",
" div.style.color = 'darkred';\n",
" div.textContent = 'Error loading resource letsPlotJs';\n",
" document.getElementById(\"kotlin_out_1\").appendChild(div);\n",
" }, false);\n",
" \n",
" e.appendChild(script);\n",
" });\n",
" })();\n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%useLatestDescriptors\n",
"%use dataframe\n",
"%use lets-plot"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "81b92ef6-3141-482d-9adf-3313be01ed12",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:02.497884Z",
"iopub.status.busy": "2025-12-03T16:05:02.497609Z",
"iopub.status.idle": "2025-12-03T16:05:02.528296Z",
"shell.execute_reply": "2025-12-03T16:05:02.528085Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Lets-Plot Kotlin API v.4.12.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.8.1.\n",
"Outputs: Web (HTML+JS), Kotlin Notebook (Swing), Static SVG (hidden)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LetsPlot.getInfo()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ea3ced8d-e043-4373-8f4e-077fba64da34",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:02.530929Z",
"iopub.status.busy": "2025-12-03T16:05:02.530426Z",
"iopub.status.idle": "2025-12-03T16:05:02.553508Z",
"shell.execute_reply": "2025-12-03T16:05:02.553094Z"
}
},
"outputs": [],
"source": [
"import kotlin.random.Random\n",
"import org.jetbrains.letsPlot.interact.ggtb"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3ca6c904-55aa-454e-ab16-b121d9100acb",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:02.556056Z",
"iopub.status.busy": "2025-12-03T16:05:02.555571Z",
"iopub.status.idle": "2025-12-03T16:05:03.484858Z",
"shell.execute_reply": "2025-12-03T16:05:03.484626Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"32 x 12\n",
" model mpg cyl disp hp drat wt qsec vs am gear carb\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1 Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 3 Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 4 Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2\n",
"\n"
]
}
],
"source": [
"val df = DataFrame.readCsv(\n",
" fileOrUrl = \"https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv\",\n",
" delimiter = ',',\n",
" header = listOf(),\n",
" colTypes = mapOf(),\n",
" skipLines = 0,\n",
" readLines = null,\n",
" allowMissingColumns = true,\n",
" parserOptions = null\n",
")\n",
"println(df.size())\n",
"println(df.head())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a9a5c1ee-a055-47f2-8de7-bdb54f608171",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:03.487095Z",
"iopub.status.busy": "2025-12-03T16:05:03.486889Z",
"iopub.status.idle": "2025-12-03T16:05:03.757737Z",
"shell.execute_reply": "2025-12-03T16:05:03.757471Z"
}
},
"outputs": [],
"source": [
"val df1 = df.filter { (2.0 < it[\"wt\"] as Double) && ((it[\"wt\"] as Double) < 3.65) }\n",
"val df2 = df\n",
" .filter { (2.0 < it[\"wt\"] as Double) && ((it[\"wt\"] as Double) < 3) }\n",
" .add(\"shape\") { if (it[\"am\"] == 0.0) 16 else 21 }"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "35dfc501-3dff-48de-b1ae-dac2f3f86dad",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:03.759010Z",
"iopub.status.busy": "2025-12-03T16:05:03.758895Z",
"iopub.status.idle": "2025-12-03T16:05:03.831332Z",
"shell.execute_reply": "2025-12-03T16:05:03.831134Z"
}
},
"outputs": [],
"source": [
"val plot1 = ggplot(df1.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" } + geomPoint(color = \"red\")\n",
"val plot2 = ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" } + geomPoint(color = \"red\")"
]
},
{
"cell_type": "markdown",
"id": "f3c89c08-29a5-4a30-bd6e-a5d157665d9b",
"metadata": {},
"source": [
"### Comparison of geomText() and geomTextRepel()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d49a03c5-8719-46ab-a8bd-5f918f868042",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:03.832597Z",
"iopub.status.busy": "2025-12-03T16:05:03.832368Z",
"iopub.status.idle": "2025-12-03T16:05:03.974797Z",
"shell.execute_reply": "2025-12-03T16:05:03.974571Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"hh55cX\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"hh55cX\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"geomText()\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"1\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"geomTextRepel()\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"2\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomText() + ggtitle(\"geomText()\"),\n",
" plot2 + geomTextRepel() + ggtitle(\"geomTextRepel()\")\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "1de52948-f9d2-49be-8c22-b264c52038fd",
"metadata": {},
"source": [
"### geomLabelRepel()\n",
"All of the parameters discussed below apply equally to both `geomTextRepel()` and `geomLabelRepel()`. For simplicity, we will use `geomTextRepel()` in the examples."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "12b29f79-b837-445b-ac17-7828818ad354",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:03.976031Z",
"iopub.status.busy": "2025-12-03T16:05:03.975825Z",
"iopub.status.idle": "2025-12-03T16:05:04.027337Z",
"shell.execute_reply": "2025-12-03T16:05:04.027098Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"YERFtp\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"YERFtp\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"geomText()\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"label\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"3\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"geomTextRepel()\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"label_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"4\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomLabel() + ggtitle(\"geomText()\"),\n",
" plot2 + geomLabelRepel() + ggtitle(\"geomTextRepel()\")\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "e5f55b41-8d5f-497f-b88d-56bbf55b7523",
"metadata": {},
"source": [
"### `seed` parameter\n",
"\n",
"Controls the randomization to produce the same label layout each time the plot is generated."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "6e31322c-0405-41fc-a739-bb6cccdce904",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.028560Z",
"iopub.status.busy": "2025-12-03T16:05:04.028364Z",
"iopub.status.idle": "2025-12-03T16:05:04.092975Z",
"shell.execute_reply": "2025-12-03T16:05:04.092746Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"iHAwmV\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"iHAwmV\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":2,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"Without seed\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"5\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"Without seed\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"6\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"With seed\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":4.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"7\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"With seed\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":4.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"8\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomTextRepel() + ggtitle(\"Without seed\"),\n",
" plot2 + geomTextRepel() + ggtitle(\"Without seed\"),\n",
" plot2 + geomTextRepel(seed = 4) + ggtitle(\"With seed\"),\n",
" plot2 + geomTextRepel(seed = 4) + ggtitle(\"With seed\"),\n",
" ), ncol = 2\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "5017d288-3742-45c3-93ee-babc013fd01f",
"metadata": {},
"source": [
"In some cases, it may be necessary to find a seed value that produces a more optimal label arrangement. A simple approach is to re-render the plot multiple times until you're satisfied with the result, then use the corresponding seed to reproduce it."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "ab48d9d3-dc79-4962-81a9-447ef179e3da",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.094121Z",
"iopub.status.busy": "2025-12-03T16:05:04.093988Z",
"iopub.status.idle": "2025-12-03T16:05:04.147881Z",
"shell.execute_reply": "2025-12-03T16:05:04.147698Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"eeXmRf\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"eeXmRf\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"ggtitle\":{\n",
"\"text\":\"Seed = 147079684\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":1.47079684E8,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"9\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"seed = 147079684"
]
}
],
"source": [
"val randomSeed = Random.nextInt()\n",
"print(\"seed = $randomSeed\")\n",
"(plot2 + geomTextRepel(seed = randomSeed) + ggtitle(\"Seed = $randomSeed\")).show()"
]
},
{
"cell_type": "markdown",
"id": "4f91e730-949e-4659-b720-42fde24084a0",
"metadata": {},
"source": [
"### `maxIter` parameter\n",
"\n",
"Controls the maximum number of iterations used by the layout algorithm, helping to reduce notebook rendering time. More iterations generally lead to better label placement, but at the cost of increased computation time. For plots with a small number of labels, 200–300 iterations are often sufficient.\n",
"The default value is 2000."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "bcbce3ae-4a20-40aa-bd88-8b01e1564d1e",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.149051Z",
"iopub.status.busy": "2025-12-03T16:05:04.148863Z",
"iopub.status.idle": "2025-12-03T16:05:04.205357Z",
"shell.execute_reply": "2025-12-03T16:05:04.205117Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"7JodBq\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"7JodBq\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":3,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_iter=2\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"max_iter\":2.0,\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"10\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_iter=20\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"max_iter\":20.0,\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"11\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_iter=200\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"max_iter\":200.0,\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"12\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val seed = 530\n",
"gggrid(\n",
" listOf(\n",
" plot2 + geomTextRepel(seed = seed, maxIter = 2) + ggtitle(\"max_iter=2\"),\n",
" plot2 + geomTextRepel(seed = seed, maxIter = 20) + ggtitle(\"max_iter=20\"),\n",
" plot2 + geomTextRepel(seed = seed, maxIter = 200) + ggtitle(\"max_iter=200\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "0694f1fd-2144-4179-af25-ee9180c6f349",
"metadata": {},
"source": [
"### `maxTime` parameter\n",
"\n",
"Another way to limit plot rendering time is by using the `maxTime` parameter. This primarily serves as a safeguard against excessive computation when a large number of text labels are involved. Time is specified in seconds. The default value is `5` seconds, but you can disable the time limit by setting it to `-1` if needed."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "6a7e7d37-3426-44c7-b297-d391b1fa1142",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.206572Z",
"iopub.status.busy": "2025-12-03T16:05:04.206382Z",
"iopub.status.idle": "2025-12-03T16:05:04.262346Z",
"shell.execute_reply": "2025-12-03T16:05:04.262122Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"lTM9fb\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"lTM9fb\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":3,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_time=0.001\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":0.001,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"13\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_time=0.01\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":0.01,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"14\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"max_time=-1\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"15\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomTextRepel(seed = seed, maxTime = 0.001) + ggtitle(\"max_time=0.001\"),\n",
" plot2 + geomTextRepel(seed = seed, maxTime = 0.01) + ggtitle(\"max_time=0.01\"),\n",
" plot2 + geomTextRepel(seed = seed, maxTime = -1.0) + ggtitle(\"max_time=-1\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "fb6279e2-36ed-4991-9918-066a98e092c1",
"metadata": {},
"source": [
"### `direction` parameter\n",
"\n",
"Restricts the movement of a text label relative to its anchor point to a specific direction. The default value is `both`."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "a64f29ce-417c-4d32-88c1-fee074711f56",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.264322Z",
"iopub.status.busy": "2025-12-03T16:05:04.264084Z",
"iopub.status.idle": "2025-12-03T16:05:04.333726Z",
"shell.execute_reply": "2025-12-03T16:05:04.333468Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"Q11V4x\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"Q11V4x\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":3,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"direction = 'x'\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"direction\":\"x\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"16\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"direction = 'y'\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"direction\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"17\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"direction = 'both'\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"direction\":\"both\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"18\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomTextRepel(seed = seed, direction = \"x\") + ggtitle(\"direction = 'x'\"),\n",
" plot2 + geomTextRepel(seed = seed, direction = \"y\") + ggtitle(\"direction = 'y'\"),\n",
" plot2 + geomTextRepel(seed = seed, direction = \"both\") + ggtitle(\"direction = 'both'\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "6f770d41-6840-4926-84a5-c1e87418b573",
"metadata": {},
"source": [
"As we can see, this option is of limited use for randomly scattered points, but in certain cases it can be extremely helpful:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "1689cd18-3d39-44ec-b35c-94a58baef036",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.335588Z",
"iopub.status.busy": "2025-12-03T16:05:04.335391Z",
"iopub.status.idle": "2025-12-03T16:05:04.451367Z",
"shell.execute_reply": "2025-12-03T16:05:04.451153Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"4SA8ci\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"4SA8ci\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"direction = x\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[2.0,3.0]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[1.0,1.3]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"y\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"nudge_y\":0.05,\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"y\":1.0,\n",
"\"angle\":90.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"hjust\":0.0,\n",
"\"direction\":\"x\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"19\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"direction = y\"\n",
"},\n",
"\"mapping\":{\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[0.9,1.3]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[19.0,35.0]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"nudge_x\":0.05,\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"hjust\":0.0,\n",
"\"direction\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"20\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plotX = ggplot(df2.toMap()) { x = \"wt\"; label = \"model\" } +\n",
" geomPoint(y = 1, color = \"red\") + xlim(2 to 3) + ylim(1 to 1.3) +\n",
" geomTextRepel(y = 1, nudgeY = 0.05, direction = \"x\", angle = 90, hjust = 0.0, seed = seed)\n",
"\n",
"val plotY = ggplot(df2.toMap()) { y = \"mpg\"; label = \"model\" } +\n",
" geomPoint(x = 1, color = \"red\") + xlim(0.9 to 1.3) + ylim(19 to 35) +\n",
" geomTextRepel(x = 1, nudgeX = 0.05, direction = \"y\", hjust = 0.0, seed = seed)\n",
"\n",
"gggrid(\n",
" listOf(\n",
" plotX + ggtitle(\"direction = x\"),\n",
" plotY + ggtitle(\"direction = y\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "47a85094-deb1-42e1-9f20-fbfc2b881b15",
"metadata": {},
"source": [
"### `pointPadding` and `boxPadding` parameters\n",
"\n",
"These parameters control the amount of spacing around text labels.\n",
"\n",
"- `pointPadding` adds space between the label and all nearby points, but does not affect spacing between labels.\n",
"\n",
"- `boxPadding` adds space between labels, but does not affect spacing between the label and the data point."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f8dd256e-0371-4b2e-ab93-aeecb4a6560d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.453230Z",
"iopub.status.busy": "2025-12-03T16:05:04.452891Z",
"iopub.status.idle": "2025-12-03T16:05:04.496602Z",
"shell.execute_reply": "2025-12-03T16:05:04.496348Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"BkgxVC\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"BkgxVC\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"pointPadding\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_padding\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"21\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"boxPadding\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"box_padding\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"22\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot2 + geomTextRepel(seed = seed, maxTime = -1.0, pointPadding = 10) + ggtitle(\"pointPadding\"),\n",
" plot2 + geomTextRepel(seed = seed, maxTime = -1.0, boxPadding = 10) + ggtitle(\"boxPadding\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "a9cfeffe-aed8-47e6-8a26-a73c958a65dc",
"metadata": {},
"source": [
"### `maxOverlaps` parameter\n",
"\n",
"Specifies the maximum allowed number of overlaps with other labels. Labels that exceed this threshold will be omitted from the plot. The default value is `10`. You can disable overlap filtering entirely by setting this parameter to `-1`."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "60ced1e9-99ea-49e0-8bb7-3b6952e9f64f",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.498436Z",
"iopub.status.busy": "2025-12-03T16:05:04.498230Z",
"iopub.status.idle": "2025-12-03T16:05:04.548767Z",
"shell.execute_reply": "2025-12-03T16:05:04.548493Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"g0owm5\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"g0owm5\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"maxOverlaps=5\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,21.4,18.7,18.1,14.3,24.4,22.8,19.2,17.8,32.4,21.5,15.5,15.2,26.0,15.8,19.7,15.0,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Hornet 4 Drive\",\"Hornet Sportabout\",\"Valiant\",\"Duster 360\",\"Merc 240D\",\"Merc 230\",\"Merc 280\",\"Merc 280C\",\"Fiat 128\",\"Toyota Corona\",\"Dodge Challenger\",\"AMC Javelin\",\"Porsche 914-2\",\"Ford Pantera L\",\"Ferrari Dino\",\"Maserati Bora\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,3.215,3.44,3.46,3.57,3.19,3.15,3.44,3.44,2.2,2.465,3.52,3.435,2.14,3.17,2.77,3.57,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"max_overlaps\":5.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"23\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"maxOverlaps=-1\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,21.4,18.7,18.1,14.3,24.4,22.8,19.2,17.8,32.4,21.5,15.5,15.2,26.0,15.8,19.7,15.0,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Hornet 4 Drive\",\"Hornet Sportabout\",\"Valiant\",\"Duster 360\",\"Merc 240D\",\"Merc 230\",\"Merc 280\",\"Merc 280C\",\"Fiat 128\",\"Toyota Corona\",\"Dodge Challenger\",\"AMC Javelin\",\"Porsche 914-2\",\"Ford Pantera L\",\"Ferrari Dino\",\"Maserati Bora\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,3.215,3.44,3.46,3.57,3.19,3.15,3.44,3.44,2.2,2.465,3.52,3.435,2.14,3.17,2.77,3.57,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"max_overlaps\":-1.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"24\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot1 + geomTextRepel(seed = seed, maxTime = -1.0, maxOverlaps = 5) + ggtitle(\"maxOverlaps=5\"),\n",
" plot1 + geomTextRepel(seed = seed, maxTime = -1.0, maxOverlaps = -1) + ggtitle(\"maxOverlaps=-1\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "f4ff9886-b49f-46b9-8541-e8bf80b41ad1",
"metadata": {},
"source": [
"### `minSegmentLength` parameter\n",
"\n",
"Sets the minimum length for the line connecting a label to its associated point. Lines shorter than this length will not be drawn. To display all lines, use the default value of `0`. To hide all lines, set the value to something very large.\n",
"`minSegmentLength` uses the same units as `pointSize`, so be careful when using `minSegmentLength` together with `sizeUnit` (see below)."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "bcd4fd08-dab7-487e-a927-7d71df037a75",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.550346Z",
"iopub.status.busy": "2025-12-03T16:05:04.550077Z",
"iopub.status.idle": "2025-12-03T16:05:04.603032Z",
"shell.execute_reply": "2025-12-03T16:05:04.602832Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"kc1SnC\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"kc1SnC\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"minSegmentLength=0\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,21.4,18.7,18.1,14.3,24.4,22.8,19.2,17.8,32.4,21.5,15.5,15.2,26.0,15.8,19.7,15.0,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Hornet 4 Drive\",\"Hornet Sportabout\",\"Valiant\",\"Duster 360\",\"Merc 240D\",\"Merc 230\",\"Merc 280\",\"Merc 280C\",\"Fiat 128\",\"Toyota Corona\",\"Dodge Challenger\",\"AMC Javelin\",\"Porsche 914-2\",\"Ford Pantera L\",\"Ferrari Dino\",\"Maserati Bora\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,3.215,3.44,3.46,3.57,3.19,3.15,3.44,3.44,2.2,2.465,3.52,3.435,2.14,3.17,2.77,3.57,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"min_segment_length\":0.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"25\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"minSegmentLength=9999\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,21.4,18.7,18.1,14.3,24.4,22.8,19.2,17.8,32.4,21.5,15.5,15.2,26.0,15.8,19.7,15.0,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Hornet 4 Drive\",\"Hornet Sportabout\",\"Valiant\",\"Duster 360\",\"Merc 240D\",\"Merc 230\",\"Merc 280\",\"Merc 280C\",\"Fiat 128\",\"Toyota Corona\",\"Dodge Challenger\",\"AMC Javelin\",\"Porsche 914-2\",\"Ford Pantera L\",\"Ferrari Dino\",\"Maserati Bora\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,3.215,3.44,3.46,3.57,3.19,3.15,3.44,3.44,2.2,2.465,3.52,3.435,2.14,3.17,2.77,3.57,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"min_segment_length\":9999.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"26\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gggrid(\n",
" listOf(\n",
" plot1 + geomTextRepel(seed = seed, maxTime = -1.0, minSegmentLength = 0) + ggtitle(\"minSegmentLength=0\"),\n",
" plot1 + geomTextRepel(\n",
" seed = seed,\n",
" maxTime = -1.0,\n",
" minSegmentLength = 9999\n",
" ) + ggtitle(\"minSegmentLength=9999\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "7870166b-b312-4f03-8c0d-471df42f2813",
"metadata": {},
"source": [
"## Point settings\n",
"\n",
"`geomTextRepel()` does not draw points itself, but for it to work correctly, the values of parameters and aesthetics that control point size must match those used in the associated `geomPoint()` layer."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "4fd33dd1-7a5b-4141-a83d-9cdfa32feafc",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.604744Z",
"iopub.status.busy": "2025-12-03T16:05:04.604306Z",
"iopub.status.idle": "2025-12-03T16:05:04.701513Z",
"shell.execute_reply": "2025-12-03T16:05:04.701298Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"IZhtGt\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"IZhtGt\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"shape\":[21.0,21.0,21.0,21.0,21.0,21.0,21.0,21.0],\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78],\n",
"\"vs\":[0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0],\n",
"\"gear\":[4.0,4.0,4.0,4.0,3.0,5.0,5.0,4.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"size\",\n",
"\"range\":[0.5,1.0],\n",
"\"guide\":\"none\"\n",
"},{\n",
"\"aesthetic\":\"stroke\",\n",
"\"range\":[1.0,4.0],\n",
"\"guide\":\"none\"\n",
"},{\n",
"\"aesthetic\":\"shape\",\n",
"\"discrete\":true,\n",
"\"scale_mapper_kind\":\"identity\",\n",
"\"guide\":\"none\"\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"shape\":\"shape\",\n",
"\"size\":\"gear\",\n",
"\"stroke\":\"vs\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"\"shape\":\"shape\",\n",
"\"point_size\":\"gear\",\n",
"\"point_stroke\":\"vs\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"27\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(sizeUnit = \"y\") { size = \"gear\"; stroke = \"vs\"; shape = \"shape\" }\n",
" + geomTextRepel(sizeUnit = \"y\") { pointSize = \"gear\"; pointStroke = \"vs\"; shape = \"shape\" }\n",
" + theme().legendPositionNone()\n",
" + scaleSize(range = 0.5 to 1, guide = \"none\")\n",
" + scaleStroke(range = 1 to 4, guide = \"none\")\n",
" + scaleShapeIdentity()\n",
" )\n",
" .show()"
]
},
{
"cell_type": "markdown",
"id": "d520d0fa-8329-45a6-a55f-f44a062463fd",
"metadata": {},
"source": [
"### `pointSize` aesthetic\n",
"\n",
"Allows you to pass to `geomTextRepel()` the data used to determine point sizes in a `geomPoint()` layer. This helps accurately detect overlaps between labels and points when point sizes vary."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "6f4c0ff5-0fad-441a-a297-b91627a4ef1e",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.702934Z",
"iopub.status.busy": "2025-12-03T16:05:04.702742Z",
"iopub.status.idle": "2025-12-03T16:05:04.783558Z",
"shell.execute_reply": "2025-12-03T16:05:04.783336Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"1J2Wcv\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"1J2Wcv\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without pointSize\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78],\n",
"\"gear\":[4.0,4.0,4.0,4.0,3.0,5.0,5.0,4.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"size\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"28\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with pointSize\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78],\n",
"\"gear\":[4.0,4.0,4.0,4.0,3.0,5.0,5.0,4.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"size\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"\"point_size\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"29\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot31 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(color = \"red\") { size = \"gear\" }\n",
" + theme().legendPositionNone())\n",
"\n",
"gggrid(\n",
" listOf(\n",
" plot31 + geomTextRepel(seed = seed, maxTime = -1.0) + ggtitle(\"without pointSize\"),\n",
" plot31 + geomTextRepel(seed = seed, maxTime = -1.0) { pointSize = \"gear\" } + ggtitle(\"with pointSize\"),\n",
" )).show()"
]
},
{
"cell_type": "markdown",
"id": "96b499b0-4fe8-4998-aff6-725ef02eff4f",
"metadata": {},
"source": [
"You can also provide a constant value instead."
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "7e5ce02c-ec1e-4e1b-8469-2f304b6c2e5d",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.784944Z",
"iopub.status.busy": "2025-12-03T16:05:04.784757Z",
"iopub.status.idle": "2025-12-03T16:05:04.849182Z",
"shell.execute_reply": "2025-12-03T16:05:04.848968Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"6StAjT\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"6StAjT\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without pointSize\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"30\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with pointSize\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"31\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot32 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(size = 10, color = \"red\")\n",
" + theme().legendPositionNone())\n",
"\n",
"gggrid(\n",
" listOf(\n",
" plot32 + geomTextRepel(seed = seed, maxTime = -1.0) + ggtitle(\"without pointSize\"),\n",
" plot32 + geomTextRepel(seed = seed, maxTime = -1.0, pointSize = 10) + ggtitle(\"with pointSize\"),\n",
" )\n",
").show()"
]
},
{
"cell_type": "markdown",
"id": "1f038fb6-5a0c-4210-8053-01f8fc030442",
"metadata": {},
"source": [
"Set `pointSize = 0` to prevent label repulsion away from data points.\n",
"\n",
"Labels will still move away from each other and away from the edges of the plot."
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "70ad0737-eb12-4ab4-9ee7-2fd70681cad6",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:04.850701Z",
"iopub.status.busy": "2025-12-03T16:05:04.850513Z",
"iopub.status.idle": "2025-12-03T16:05:05.128047Z",
"shell.execute_reply": "2025-12-03T16:05:05.128173Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"A6BUKG\"></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
" if(!window.letsPlotCallQueue) {\n",
" window.letsPlotCallQueue = [];\n",
" }; \n",
" window.letsPlotCall = function(f) {\n",
" window.letsPlotCallQueue.push(f);\n",
" };\n",
" (function() {\n",
" var script = document.createElement(\"script\");\n",
" script.type = \"text/javascript\";\n",
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.8.1/js-package/distr/lets-plot.min.js\";\n",
" script.onload = function() {\n",
" window.letsPlotCall = function(f) {f();};\n",
" window.letsPlotCallQueue.forEach(function(f) {f();});\n",
" window.letsPlotCallQueue = [];\n",
" \n",
" \n",
" };\n",
" script.onerror = function(event) {\n",
" window.letsPlotCall = function(f) {};\n",
" window.letsPlotCallQueue = [];\n",
" var div = document.createElement(\"div\");\n",
" div.style.color = 'darkred';\n",
" div.textContent = 'Error loading Lets-Plot JS';\n",
" document.getElementById(\"A6BUKG\").appendChild(div);\n",
" };\n",
" var e = document.getElementById(\"A6BUKG\");\n",
" e.appendChild(script);\n",
" })();\n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/plot+json": {
"apply_color_scheme": true,
"output": {
"figures": [
{
"data": {
"am": [
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
1.0,
1.0
],
"carb": [
4.0,
4.0,
1.0,
1.0,
1.0,
2.0,
6.0,
2.0
],
"cyl": [
6.0,
6.0,
4.0,
4.0,
4.0,
4.0,
6.0,
4.0
],
"disp": [
160.0,
160.0,
108.0,
78.7,
120.1,
120.3,
145.0,
121.0
],
"drat": [
3.9,
3.9,
3.85,
4.08,
3.7,
4.43,
3.62,
4.11
],
"gear": [
4.0,
4.0,
4.0,
4.0,
3.0,
5.0,
5.0,
4.0
],
"hp": [
110.0,
110.0,
93.0,
66.0,
97.0,
91.0,
175.0,
109.0
],
"model": [
"Mazda RX4",
"Mazda RX4 Wag",
"Datsun 710",
"Fiat 128",
"Toyota Corona",
"Porsche 914-2",
"Ferrari Dino",
"Volvo 142E"
],
"mpg": [
21.0,
21.0,
22.8,
32.4,
21.5,
26.0,
19.7,
21.4
],
"qsec": [
16.46,
17.02,
18.61,
19.47,
20.01,
16.7,
15.5,
18.6
],
"shape": [
21.0,
21.0,
21.0,
21.0,
21.0,
21.0,
21.0,
21.0
],
"vs": [
0.0,
0.0,
1.0,
1.0,
1.0,
0.0,
0.0,
1.0
],
"wt": [
2.62,
2.875,
2.32,
2.2,
2.465,
2.14,
2.77,
2.78
]
},
"data_meta": {
"series_annotations": [
{
"column": "model",
"type": "str"
},
{
"column": "mpg",
"type": "float"
},
{
"column": "cyl",
"type": "int"
},
{
"column": "disp",
"type": "float"
},
{
"column": "hp",
"type": "int"
},
{
"column": "drat",
"type": "float"
},
{
"column": "wt",
"type": "float"
},
{
"column": "qsec",
"type": "float"
},
{
"column": "vs",
"type": "int"
},
{
"column": "am",
"type": "int"
},
{
"column": "gear",
"type": "int"
},
{
"column": "carb",
"type": "int"
},
{
"column": "shape",
"type": "int"
}
]
},
"ggtitle": {
"text": "without pointSize"
},
"kind": "plot",
"layers": [
{
"color": "red",
"geom": "point",
"mapping": {},
"position": "identity",
"stat": "identity"
},
{
"geom": "text_repel",
"mapping": {},
"max_time": -1.0,
"position": "identity",
"seed": 530.0,
"stat": "identity"
}
],
"mapping": {
"label": "model",
"x": "wt",
"y": "mpg"
},
"scales": []
},
{
"data": {
"am": [
1.0,
1.0,
1.0,
1.0,
0.0,
1.0,
1.0,
1.0
],
"carb": [
4.0,
4.0,
1.0,
1.0,
1.0,
2.0,
6.0,
2.0
],
"cyl": [
6.0,
6.0,
4.0,
4.0,
4.0,
4.0,
6.0,
4.0
],
"disp": [
160.0,
160.0,
108.0,
78.7,
120.1,
120.3,
145.0,
121.0
],
"drat": [
3.9,
3.9,
3.85,
4.08,
3.7,
4.43,
3.62,
4.11
],
"gear": [
4.0,
4.0,
4.0,
4.0,
3.0,
5.0,
5.0,
4.0
],
"hp": [
110.0,
110.0,
93.0,
66.0,
97.0,
91.0,
175.0,
109.0
],
"model": [
"Mazda RX4",
"Mazda RX4 Wag",
"Datsun 710",
"Fiat 128",
"Toyota Corona",
"Porsche 914-2",
"Ferrari Dino",
"Volvo 142E"
],
"mpg": [
21.0,
21.0,
22.8,
32.4,
21.5,
26.0,
19.7,
21.4
],
"qsec": [
16.46,
17.02,
18.61,
19.47,
20.01,
16.7,
15.5,
18.6
],
"shape": [
21.0,
21.0,
21.0,
21.0,
21.0,
21.0,
21.0,
21.0
],
"vs": [
0.0,
0.0,
1.0,
1.0,
1.0,
0.0,
0.0,
1.0
],
"wt": [
2.62,
2.875,
2.32,
2.2,
2.465,
2.14,
2.77,
2.78
]
},
"data_meta": {
"series_annotations": [
{
"column": "model",
"type": "str"
},
{
"column": "mpg",
"type": "float"
},
{
"column": "cyl",
"type": "int"
},
{
"column": "disp",
"type": "float"
},
{
"column": "hp",
"type": "int"
},
{
"column": "drat",
"type": "float"
},
{
"column": "wt",
"type": "float"
},
{
"column": "qsec",
"type": "float"
},
{
"column": "vs",
"type": "int"
},
{
"column": "am",
"type": "int"
},
{
"column": "gear",
"type": "int"
},
{
"column": "carb",
"type": "int"
},
{
"column": "shape",
"type": "int"
}
]
},
"ggtitle": {
"text": "with pointSize = 0"
},
"kind": "plot",
"layers": [
{
"color": "red",
"geom": "point",
"mapping": {},
"position": "identity",
"stat": "identity"
},
{
"geom": "text_repel",
"mapping": {},
"max_time": -1.0,
"point_size": 0.0,
"position": "identity",
"seed": 530.0,
"stat": "identity"
}
],
"mapping": {
"label": "model",
"x": "wt",
"y": "mpg"
},
"scales": []
}
],
"kind": "subplots",
"layout": {
"align": false,
"fit": true,
"name": "grid",
"ncol": 2,
"nrow": 1
}
},
"output_type": "lets_plot_spec",
"swing_enabled": true
},
"text/html": [
" <div id=\"HDOEab\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"HDOEab\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without pointSize\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"32\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with pointSize = 0\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_size\":0.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"33\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script> <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" display=\"block\" class=\"plt-container\" id=5e4f2250-3144-4fdf-87cb-82260b72854e width=\"100%\" height=\"100%\" style=\"max-width: 900.0px; max-height: 400.0px;\" viewBox=\"0 0 900.0 400.0\" preserveAspectRatio=\"xMinYMin meet\">\n",
" <style type=\"text/css\">\n",
" .plt-container {\n",
" font-family: sans-serif;\n",
" user-select: none;\n",
" -webkit-user-select: none;\n",
" -moz-user-select: none;\n",
" -ms-user-select: none;\n",
"}\n",
"text {\n",
" text-rendering: optimizeLegibility;\n",
"}\n",
"#pvGCph2 .plot-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 16.0px;\n",
"\n",
"}\n",
"#pvGCph2 .plot-subtitle {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pvGCph2 .plot-caption {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pvGCph2 .hyperlink-element {\n",
"fill: #118ed8;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"\n",
"}\n",
"#pvGCph2 .legend-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pvGCph2 .legend-item {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pvGCph2 .axis-title-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pvGCph2 .axis-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
".axis-tooltip-text-x {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pvGCph2 .axis-title-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pvGCph2 .axis-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
".axis-tooltip-text-y {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pvGCph2 .facet-strip-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pvGCph2 .facet-strip-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
".tooltip-text {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
".tooltip-title {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
".tooltip-label {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"\n",
" </style>\n",
" <g id=\"pvGCph2\">\n",
" <rect x=\"0.0\" y=\"0.0\" height=\"400.0\" width=\"900.0\" fill=\"rgb(255,255,255)\" fill-opacity=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" stroke-width=\"0.0\">\n",
" </rect>\n",
" </g>\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" display=\"block\" class=\"plt-container\" width=\"442.0\" height=\"388.0\" x=\"6.0\" y=\"6.0\">\n",
" <style type=\"text/css\">\n",
" .plt-container {\n",
" font-family: sans-serif;\n",
" user-select: none;\n",
" -webkit-user-select: none;\n",
" -moz-user-select: none;\n",
" -ms-user-select: none;\n",
"}\n",
"text {\n",
" text-rendering: optimizeLegibility;\n",
"}\n",
"#pZt7OXj .plot-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 16.0px;\n",
"\n",
"}\n",
"#pZt7OXj .plot-subtitle {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pZt7OXj .plot-caption {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pZt7OXj .hyperlink-element {\n",
"fill: #118ed8;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"\n",
"}\n",
"#pZt7OXj .legend-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pZt7OXj .legend-item {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pZt7OXj .axis-title-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pZt7OXj .axis-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#d85wCTG .axis-tooltip-text-x {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pZt7OXj .axis-title-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pZt7OXj .axis-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#d85wCTG .axis-tooltip-text-y {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pZt7OXj .facet-strip-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pZt7OXj .facet-strip-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#d85wCTG .tooltip-text {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#d85wCTG .tooltip-title {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#d85wCTG .tooltip-label {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"\n",
" </style>\n",
" <g id=\"pZt7OXj\">\n",
" <path fill-rule=\"evenodd\" fill=\"rgb(255,255,255)\" fill-opacity=\"1.0\" d=\"M0.0 0.0 L0.0 388.0 L442.0 388.0 L442.0 0.0 Z\">\n",
" </path>\n",
" <g transform=\"translate(21.0 22.0 ) \">\n",
" <g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <line x1=\"47.512062887281445\" y1=\"0.0\" x2=\"47.512062887281445\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"145.72821355866404\" y1=\"0.0\" x2=\"145.72821355866404\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"243.9443642300464\" y1=\"0.0\" x2=\"243.9443642300464\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"342.160514901429\" y1=\"0.0\" x2=\"342.160514901429\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <line x1=\"0.0\" y1=\"304.1811023622047\" x2=\"397.0387890890636\" y2=\"304.1811023622047\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"257.5096635647816\" x2=\"397.0387890890636\" y2=\"257.5096635647816\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"210.8382247673585\" x2=\"397.0387890890636\" y2=\"210.8382247673585\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"164.16678596993552\" x2=\"397.0387890890636\" y2=\"164.16678596993552\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"117.49534717251242\" x2=\"397.0387890890636\" y2=\"117.49534717251242\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"70.82390837508945\" x2=\"397.0387890890636\" y2=\"70.82390837508945\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"24.152469577666352\" x2=\"397.0387890890636\" y2=\"24.152469577666352\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g clip-path=\"url(#c2Ja48j)\" clip-bounds-jfx=\"[rect (17.961210910936405, 0.0), (397.0387890890636, 326.0)]\">\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <g>\n",
" <g>\n",
" <g >\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"253.76597929718446\" cy=\"280.84538296349314\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"378.991571403197\" cy=\"280.84538296349314\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"106.44175329011068\" cy=\"238.8410880458124\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"47.512062887281445\" cy=\"14.818181818181756\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"177.6484625268629\" cy=\"269.1775232641374\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"18.0472176858666\" cy=\"164.16678596993552\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"327.42809230072135\" cy=\"311.18181818181813\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"332.33889983429026\" cy=\"271.51109520400854\" r=\"3.3000000000000003\" />\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <g transform=\"rotate(0.0 210.84702798533618 280.24142144324986 ) \">\n",
" <g transform=\"translate(210.84702798533618 284.44142144324985 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Mazda RX4</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"250.61011665158708\" y1=\"279.8807426356384\" x2=\"251.79009300456732\" y2=\"280.24142144324986\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 319.2408499376772 291.3578421124357 ) \">\n",
" <g transform=\"translate(319.2408499376772 295.5578421124357 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Mazda RX4 Wag</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"378.98162693042946\" y1=\"284.14536797974114\" x2=\"378.9598922097432\" y2=\"291.3578421124357\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 87.46425768550884 250.74364121976893 ) \">\n",
" <g transform=\"translate(87.46425768550884 254.94364121976892 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Datsun 710</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"103.24664740011053\" y1=\"239.66649603686187\" x2=\"87.46425768550876\" y2=\"243.74364121976885\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 82.10587309148137 12.573605318931962 ) \">\n",
" <g transform=\"translate(82.10587309148137 16.773605318931963 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Fiat 128</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"50.51353094488809\" y1=\"13.446617200977244\" x2=\"52.423989442432685\" y2=\"12.573605318931982\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 187.26007624064428 258.4513228259856 ) \">\n",
" <g transform=\"translate(187.26007624064428 262.6513228259856 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Toyota Corona</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"180.7253359638114\" y1=\"267.98469056295886\" x2=\"187.26007624064414\" y2=\"265.4513228259857\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 61.14045562668503 153.67399029907776 ) \">\n",
" <g transform=\"translate(61.14045562668503 157.87399029907775 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Porsche 914-2</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"21.336431232670293\" y1=\"163.90018843895905\" x2=\"61.1404556266848\" y2=\"160.6739902990778\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 281.42780192718874 311.3568727917247 ) \">\n",
" <g transform=\"translate(281.42780192718874 315.5568727917247 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Ferrari Dino</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"324.1406247287159\" y1=\"311.46914545691266\" x2=\"325.42519733292306\" y2=\"311.3568727917247\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 323.6676388983125 260.1406633883714 ) \">\n",
" <g transform=\"translate(323.6676388983125 264.3406633883714 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Volvo 142E</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"329.39203606094793\" y1=\"270.025836337224\" x2=\"323.6676388983126\" y2=\"267.1406633883714\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <defs>\n",
" <clipPath id=\"cjrG52s\">\n",
" <rect x=\"17.961210910936405\" y=\"0.0\" width=\"397.0387890890636\" height=\"326.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" <defs>\n",
" <clipPath id=\"c2Ja48j\">\n",
" <rect x=\"17.961210910936405\" y=\"0.0\" width=\"397.0387890890636\" height=\"326.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" </g>\n",
" <g>\n",
" <g transform=\"translate(17.961210910936405 326.0 ) \">\n",
" <g transform=\"translate(47.512062887281445 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.2</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(145.72821355866404 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.4</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(243.9443642300464 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.6</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(342.160514901429 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.8</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <line x1=\"0.0\" y1=\"0.0\" x2=\"397.0387890890636\" y2=\"0.0\" stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g transform=\"translate(0.0 304.1811023622047 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>20</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 257.5096635647816 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>22</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 210.8382247673585 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>24</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 164.16678596993552 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>26</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 117.49534717251242 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>28</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 70.82390837508945 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>30</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 24.152469577666352 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>32</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(38.9612109109364 15.8 ) \">\n",
" <text style=\"font-size:16.0px;\" y=\"0.0\" class=\"plot-title\">\n",
" <tspan>without pointSize</tspan>\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(15.0 185.0 ) rotate(-90.0 ) \">\n",
" <text style=\"font-size:15.0px;\" y=\"0.0\" class=\"axis-title-y\" text-anchor=\"middle\">\n",
" <tspan>mpg</tspan>\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(237.4806054554682 382.0 ) \">\n",
" <text style=\"font-size:15.0px;\" y=\"0.0\" class=\"axis-title-x\" text-anchor=\"middle\">\n",
" <tspan>wt</tspan>\n",
" </text>\n",
" </g>\n",
" <path fill=\"rgb(0,0,0)\" fill-opacity=\"0.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" stroke-width=\"0.0\" d=\"M0.0 0.0 L0.0 388.0 L442.0 388.0 L442.0 0.0 Z\" pointer-events=\"none\">\n",
" </path>\n",
" </g>\n",
" <g id=\"d85wCTG\">\n",
" </g>\n",
" </svg>\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" display=\"block\" class=\"plt-container\" width=\"442.0\" height=\"388.0\" x=\"452.0\" y=\"6.0\">\n",
" <style type=\"text/css\">\n",
" .plt-container {\n",
" font-family: sans-serif;\n",
" user-select: none;\n",
" -webkit-user-select: none;\n",
" -moz-user-select: none;\n",
" -ms-user-select: none;\n",
"}\n",
"text {\n",
" text-rendering: optimizeLegibility;\n",
"}\n",
"#pYZ5XkV .plot-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 16.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .plot-subtitle {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .plot-caption {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .hyperlink-element {\n",
"fill: #118ed8;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"\n",
"}\n",
"#pYZ5XkV .legend-title {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .legend-item {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .axis-title-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .axis-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#doCpTUn .axis-tooltip-text-x {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .axis-title-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 15.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .axis-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#doCpTUn .axis-tooltip-text-y {\n",
"fill: #ffffff;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .facet-strip-text-x {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#pYZ5XkV .facet-strip-text-y {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#doCpTUn .tooltip-text {\n",
"fill: #474747;\n",
"font-weight: normal;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#doCpTUn .tooltip-title {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"#doCpTUn .tooltip-label {\n",
"fill: #474747;\n",
"font-weight: bold;\n",
"font-style: normal;\n",
"font-family: sans-serif;\n",
"font-size: 13.0px;\n",
"\n",
"}\n",
"\n",
" </style>\n",
" <g id=\"pYZ5XkV\">\n",
" <path fill-rule=\"evenodd\" fill=\"rgb(255,255,255)\" fill-opacity=\"1.0\" d=\"M0.0 0.0 L0.0 388.0 L442.0 388.0 L442.0 0.0 Z\">\n",
" </path>\n",
" <g transform=\"translate(21.0 22.0 ) \">\n",
" <g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <line x1=\"47.512062887281445\" y1=\"0.0\" x2=\"47.512062887281445\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"145.72821355866404\" y1=\"0.0\" x2=\"145.72821355866404\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"243.9443642300464\" y1=\"0.0\" x2=\"243.9443642300464\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"342.160514901429\" y1=\"0.0\" x2=\"342.160514901429\" y2=\"326.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <line x1=\"0.0\" y1=\"304.1811023622047\" x2=\"397.0387890890636\" y2=\"304.1811023622047\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"257.5096635647816\" x2=\"397.0387890890636\" y2=\"257.5096635647816\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"210.8382247673585\" x2=\"397.0387890890636\" y2=\"210.8382247673585\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"164.16678596993552\" x2=\"397.0387890890636\" y2=\"164.16678596993552\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"117.49534717251242\" x2=\"397.0387890890636\" y2=\"117.49534717251242\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"70.82390837508945\" x2=\"397.0387890890636\" y2=\"70.82390837508945\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"24.152469577666352\" x2=\"397.0387890890636\" y2=\"24.152469577666352\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\" fill=\"none\">\n",
" </line>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g clip-path=\"url(#coHHmxz)\" clip-bounds-jfx=\"[rect (17.961210910936405, 0.0), (397.0387890890636, 326.0)]\">\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g>\n",
" <g>\n",
" <g>\n",
" <g >\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"253.76597929718446\" cy=\"280.84538296349314\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"378.991571403197\" cy=\"280.84538296349314\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"106.44175329011068\" cy=\"238.8410880458124\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"47.512062887281445\" cy=\"14.818181818181756\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"177.6484625268629\" cy=\"269.1775232641374\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"18.0472176858666\" cy=\"164.16678596993552\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"327.42809230072135\" cy=\"311.18181818181813\" r=\"3.3000000000000003\" />\n",
" <circle fill=\"#ff0000\" stroke=\"#ff0000\" stroke-opacity=\"0.0\" stroke-width=\"0.0\" cx=\"332.33889983429026\" cy=\"271.51109520400854\" r=\"3.3000000000000003\" />\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <g transform=\"rotate(0.0 154.7580397381828 283.1500259912879 ) \">\n",
" <g transform=\"translate(154.7580397381828 287.3500259912879 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Mazda RX4</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"253.76597929718423\" y1=\"280.84538296349314\" x2=\"195.701104757414\" y2=\"283.150025991288\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 308.17687705197017 288.96645147163576 ) \">\n",
" <g transform=\"translate(308.17687705197017 293.16645147163575 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Mazda RX4 Wag</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"378.991571403197\" y1=\"280.84538296349314\" x2=\"367.89591932403664\" y2=\"288.9664514716358\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 106.44175329011068 238.8410880458124 ) \">\n",
" <g transform=\"translate(106.44175329011068 243.0410880458124 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Datsun 710</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"rotate(0.0 47.512062887281445 14.818181818181756 ) \">\n",
" <g transform=\"translate(47.512062887281445 19.01818181818176 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Fiat 128</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"rotate(0.0 176.68735944142827 268.9846895230851 ) \">\n",
" <g transform=\"translate(176.68735944142827 273.18468952308507 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Toyota Corona</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"rotate(0.0 83.22295387287869 164.16678596993552 ) \">\n",
" <g transform=\"translate(83.22295387287869 168.3667859699355 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Porsche 914-2</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g>\n",
" <line x1=\"18.04721768586637\" y1=\"164.16678596993563\" x2=\"29.484170864042653\" y2=\"164.16678596993563\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" fill=\"none\" stroke-width=\"1.6500000000000001\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"rotate(0.0 327.42809230072135 311.18181818181813 ) \">\n",
" <g transform=\"translate(327.42809230072135 315.3818181818181 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Ferrari Dino</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"rotate(0.0 332.6748298287085 271.3410397197076 ) \">\n",
" <g transform=\"translate(332.6748298287085 275.5410397197076 ) \">\n",
" <text style=\"fill:#474747;font-size:14.0px;font-family:sans-serif;\" y=\"0.0\" fill-opacity=\"1.0\" text-anchor=\"middle\">\n",
" <tspan>Volvo 142E</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <defs>\n",
" <clipPath id=\"cLJidsJ\">\n",
" <rect x=\"17.961210910936405\" y=\"0.0\" width=\"397.0387890890636\" height=\"326.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" <defs>\n",
" <clipPath id=\"coHHmxz\">\n",
" <rect x=\"17.961210910936405\" y=\"0.0\" width=\"397.0387890890636\" height=\"326.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" </g>\n",
" <g>\n",
" <g transform=\"translate(17.961210910936405 326.0 ) \">\n",
" <g transform=\"translate(47.512062887281445 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.2</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(145.72821355866404 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.4</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(243.9443642300464 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.6</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(342.160514901429 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 6.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" <tspan>2.8</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <line x1=\"0.0\" y1=\"0.0\" x2=\"397.0387890890636\" y2=\"0.0\" stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"translate(17.961210910936405 0.0 ) \">\n",
" <g transform=\"translate(0.0 304.1811023622047 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>20</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 257.5096635647816 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>22</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 210.8382247673585 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>24</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 164.16678596993552 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>26</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 117.49534717251242 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>28</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 70.82390837508945 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>30</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 24.152469577666352 ) \">\n",
" <g transform=\"translate(-2.0 0.0 ) \">\n",
" <text style=\"font-size:13.0px;\" y=\"0.0\" class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" <tspan>32</tspan>\n",
" </text>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(38.9612109109364 15.8 ) \">\n",
" <text style=\"font-size:16.0px;\" y=\"0.0\" class=\"plot-title\">\n",
" <tspan>with pointSize = 0</tspan>\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(15.0 185.0 ) rotate(-90.0 ) \">\n",
" <text style=\"font-size:15.0px;\" y=\"0.0\" class=\"axis-title-y\" text-anchor=\"middle\">\n",
" <tspan>mpg</tspan>\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(237.4806054554682 382.0 ) \">\n",
" <text style=\"font-size:15.0px;\" y=\"0.0\" class=\"axis-title-x\" text-anchor=\"middle\">\n",
" <tspan>wt</tspan>\n",
" </text>\n",
" </g>\n",
" <path fill=\"rgb(0,0,0)\" fill-opacity=\"0.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" stroke-width=\"0.0\" d=\"M0.0 0.0 L0.0 388.0 L442.0 388.0 L442.0 0.0 Z\" pointer-events=\"none\">\n",
" </path>\n",
" </g>\n",
" <g id=\"doCpTUn\">\n",
" </g>\n",
" </svg>\n",
"</svg>\n",
" <script>document.getElementById(\"5e4f2250-3144-4fdf-87cb-82260b72854e\").style.display = \"none\";</script>"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val plot33 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(color = \"red\"))\n",
"\n",
"gggrid(\n",
" listOf(\n",
" plot33 + geomTextRepel(seed = seed, maxTime = -1.0) + ggtitle(\"without pointSize\"),\n",
" plot33 + geomTextRepel(seed = seed, maxTime = -1.0, pointSize = 0) + ggtitle(\"with pointSize = 0\"),\n",
" )\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a3701287-59a8-4b08-ad36-35ad84a7b690",
"metadata": {},
"source": [
"### `pointStroke` and `shape` aesthetics\n",
"\n",
"Allow you to pass to `geomTextRepel()` the data used to determine point stroke width and shape in a `geomPoint()` layer. This ensures accurate collision detection between labels and points."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "588e87ad-e30c-44fc-a29d-d3f6f46a10f4",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.129972Z",
"iopub.status.busy": "2025-12-03T16:05:05.129836Z",
"iopub.status.idle": "2025-12-03T16:05:05.211866Z",
"shell.execute_reply": "2025-12-03T16:05:05.211735Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"jK7elC\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"jK7elC\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without pointStroke\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78],\n",
"\"gear\":[4.0,4.0,4.0,4.0,3.0,5.0,5.0,4.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"stroke\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"shape\":21.0,\n",
"\"size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"36\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with pointStroke\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78],\n",
"\"gear\":[4.0,4.0,4.0,4.0,3.0,5.0,5.0,4.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"stroke\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"shape\":21.0,\n",
"\"size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"\"point_stroke\":\"gear\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"shape\":21.0,\n",
"\"seed\":530.0,\n",
"\"point_size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"37\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot34 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label=\"model\" }\n",
" + geomPoint(shape=21, size=10, color=\"red\") { stroke=\"gear\" }\n",
" + theme().legendPositionNone())\n",
"\n",
"gggrid(listOf(\n",
" plot34 + geomTextRepel(seed=seed, maxTime=-1.0, pointSize=10) + ggtitle(\"without pointStroke\"),\n",
" plot34 + geomTextRepel(shape=21, pointSize=10, seed=seed, maxTime=-1.0) { pointStroke=\"gear\" } + ggtitle(\"with pointStroke\"),\n",
")).show()\n"
]
},
{
"cell_type": "markdown",
"id": "6416d311-a608-40c8-a442-191882e97227",
"metadata": {},
"source": [
"### `sizeUnit` parameter\n",
"\n",
"The `sizeUnit` parameter can be used in `geomPoint()` to define the unit of measurement for the `size` aesthetic. In this case, it is recommended to also use `sizeUnit` in `geomTextRepel()` to ensure that point sizes are calculated correctly."
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "b18e356c-1418-4067-95e5-ae7245331556",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.213297Z",
"iopub.status.busy": "2025-12-03T16:05:05.213063Z",
"iopub.status.idle": "2025-12-03T16:05:05.296946Z",
"shell.execute_reply": "2025-12-03T16:05:05.296713Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"r7LC14\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"r7LC14\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without sizeUnit\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"38\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with sizeUnit\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"point_size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"39\"\n",
"}],\n",
"\"kind\":\"subplots\",\n",
"\"ggtoolbar\":{\n",
"}\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot4 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(size = 1, sizeUnit = \"y\", color = \"red\")\n",
" + theme().legendPositionNone())\n",
"\n",
"(gggrid(\n",
" listOf(\n",
" plot4 + geomTextRepel(seed = seed, maxTime = -1.0, pointSize = 1) + ggtitle(\"without sizeUnit\"),\n",
" plot4 + geomTextRepel(\n",
" seed = seed,\n",
" maxTime = -1.0,\n",
" pointSize = 1,\n",
" sizeUnit = \"y\"\n",
" ) + ggtitle(\"with sizeUnit\"),\n",
" )\n",
") + ggtb()).show()"
]
},
{
"cell_type": "markdown",
"id": "a5de7618-3475-465a-9af3-063f733dd68f",
"metadata": {},
"source": [
"##### `sizeUnit` applies to all size-related parameters: `pointSize`, `minSegmentLength`, `pointPadding`, and `boxPadding`\n",
"\n",
"As an example, consider how it affects `minSegmentLength`.\n",
"As mentioned earlier, `minSegmentLength` uses the same units as `pointSize`. Therefore, in the following example, with the same `minSegmentLength` value, some lines are not drawn in the second case because their length is less than one unit along the y-axis."
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "69063269-f4bb-43d0-ba7e-8d3e84a4cd90",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.298705Z",
"iopub.status.busy": "2025-12-03T16:05:05.298489Z",
"iopub.status.idle": "2025-12-03T16:05:05.396732Z",
"shell.execute_reply": "2025-12-03T16:05:05.396497Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"MMFLpV\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"MMFLpV\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":2,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"without sizeUnit\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"min_segment_length\":1.0,\n",
"\"point_size\":10.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"40\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"with sizeUnit\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"min_segment_length\":1.0,\n",
"\"point_size\":1.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"size_unit\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"41\"\n",
"}],\n",
"\"kind\":\"subplots\",\n",
"\"ggtoolbar\":{\n",
"}\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot5 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + theme().legendPositionNone())\n",
"\n",
"(gggrid(\n",
" listOf(\n",
" (plot5 + geomPoint(size = 10, color = \"red\")\n",
" + geomTextRepel(seed = seed, maxTime = -1.0, pointSize = 10, minSegmentLength = 1)\n",
" + ggtitle(\"without sizeUnit\")),\n",
" (plot5 + geomPoint(size = 1, sizeUnit = \"y\", color = \"red\")\n",
" + geomTextRepel(seed = seed, maxTime = -1.0, pointSize = 1, minSegmentLength = 1, sizeUnit = \"y\")\n",
" + ggtitle(\"with sizeUnit\")),\n",
" )\n",
") + ggtb()).show()"
]
},
{
"cell_type": "markdown",
"id": "3ed6370a-942e-4d3a-8c33-deada9565d7d",
"metadata": {},
"source": [
"### `segmentColor` aesthetic\n",
"\n",
"Allows you to specify the color of the line connecting the label to the point. By default, the line color matches the text color and follows the `color` aesthetic. In the example below, the `color` aesthetic is defined globally for all layers, so the colors of the points, text, and lines are the same."
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "cb322efa-8f0a-4609-b58b-a1d4b02deee4",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.398258Z",
"iopub.status.busy": "2025-12-03T16:05:05.398073Z",
"iopub.status.idle": "2025-12-03T16:05:05.444183Z",
"shell.execute_reply": "2025-12-03T16:05:05.443790Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"kOJax4\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"kOJax4\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"color\":\"wt\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"42\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\"; color = \"wt\" }\n",
" + geomPoint()\n",
" + geomTextRepel(seed = seed, maxTime = -1.0)\n",
" )\n",
" .show()"
]
},
{
"cell_type": "markdown",
"id": "868e31d0-36cc-4ef5-9304-e4d622ab5a7f",
"metadata": {},
"source": [
"By using the `color` and `segmentColor` aesthetics together, you can assign different colors to the points, labels, and connecting lines."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "23c59549-79fc-4f5d-9ff7-2c6269368144",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.445962Z",
"iopub.status.busy": "2025-12-03T16:05:05.445629Z",
"iopub.status.idle": "2025-12-03T16:05:05.554818Z",
"shell.execute_reply": "2025-12-03T16:05:05.554592Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"5iMYYe\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"5iMYYe\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"layout\":{\n",
"\"name\":\"grid\",\n",
"\"ncol\":3,\n",
"\"nrow\":1,\n",
"\"fit\":true,\n",
"\"align\":false\n",
"},\n",
"\"figures\":[{\n",
"\"ggtitle\":{\n",
"\"text\":\"Same color for points and lines\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"color\":\"wt\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"\"segment_color\":\"wt\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"43\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"Same color for text and line\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"\"color\":\"wt\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"44\"\n",
"},{\n",
"\"ggtitle\":{\n",
"\"text\":\"Different colors\"\n",
"},\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"green\",\n",
"\"seed\":530.0,\n",
"\"segment_color\":\"blue\",\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"theme\":{\n",
"\"legend_position\":\"none\"\n",
"},\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"45\"\n",
"}],\n",
"\"kind\":\"subplots\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"val plot6 = (ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + theme().legendPositionNone())\n",
"\n",
"gggrid(\n",
" listOf(\n",
" plot6 + geomPoint() { color = \"wt\" }\n",
" + geomTextRepel(seed = seed, maxTime = -1.0) { segmentColor = \"wt\" }\n",
" + ggtitle(\"Same color for points and lines\"),\n",
" plot6 + geomPoint(color = \"red\")\n",
" + geomTextRepel(seed = seed, maxTime = -1.0) { color = \"wt\" }\n",
" + ggtitle(\"Same color for text and line\"),\n",
" plot6 + geomPoint(color = \"red\")\n",
" + geomTextRepel(color = \"green\", segmentColor = \"blue\", seed = seed, maxTime = -1.0)\n",
" + ggtitle(\"Different colors\"),\n",
" )).show()"
]
},
{
"cell_type": "markdown",
"id": "de08c1f3-18c1-42af-b9cf-fdfe50e06669",
"metadata": {},
"source": [
"### `segmentAlpha` aesthetic\n",
"\n",
"Specifies the transparency level of the connecting lines between labels and points. By default, the segment transparency inherits from the text and is governed by the `alpha` aesthetic."
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "4ac608a2-3a48-4e9d-a8bf-93cadb0fcaa7",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.556322Z",
"iopub.status.busy": "2025-12-03T16:05:05.555975Z",
"iopub.status.idle": "2025-12-03T16:05:05.599442Z",
"shell.execute_reply": "2025-12-03T16:05:05.599196Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"LnWHBv\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"LnWHBv\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"seed\":530.0,\n",
"\"point_padding\":20.0,\n",
"\"segment_alpha\":0.1,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"46\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(ggplot(df2.toMap()) { x = \"wt\"; y = \"mpg\"; label = \"model\" }\n",
" + geomPoint(color = \"red\")\n",
" + geomTextRepel(pointPadding = 20, color = \"red\", segmentAlpha = 0.1, seed = seed, maxTime = -1.0)\n",
" ).show()"
]
},
{
"cell_type": "markdown",
"id": "a15e840f-4bde-4841-96b4-aeede9b10498",
"metadata": {},
"source": [
"### `segmentSize` aesthetic\n",
"\n",
"Specifies the width of the line connecting the label to the point."
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "9e20ad8d-d7a6-4001-923c-5c93b390259a",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.601159Z",
"iopub.status.busy": "2025-12-03T16:05:05.600968Z",
"iopub.status.idle": "2025-12-03T16:05:05.624329Z",
"shell.execute_reply": "2025-12-03T16:05:05.624109Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"KJDjrU\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"KJDjrU\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"x\":\"wt\",\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"wt\":[2.62,2.875,2.32,2.2,2.465,2.14,2.77,2.78]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"segment_size\":2.0,\n",
"\"seed\":530.0,\n",
"\"position\":\"identity\",\n",
"\"max_time\":-1.0,\n",
"\"geom\":\"text_repel\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"47\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(plot2 + geomTextRepel(segmentSize=2, seed=seed, maxTime=-1.0)).show()"
]
},
{
"cell_type": "markdown",
"id": "f9d213d9-beba-41ba-8625-a8d770854d65",
"metadata": {},
"source": [
"### `linetype` aesthetic"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "77421562-83f3-4f80-b572-6a45b9ab2cec",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.625956Z",
"iopub.status.busy": "2025-12-03T16:05:05.625761Z",
"iopub.status.idle": "2025-12-03T16:05:05.682599Z",
"shell.execute_reply": "2025-12-03T16:05:05.682412Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"59Rhy5\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"59Rhy5\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"],\n",
"\"disp\":[160.0,160.0,108.0,78.7,120.1,120.3,145.0,121.0]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[0.9,1.3]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[19.0,35.0]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"nudge_x\":0.2,\n",
"\"mapping\":{\n",
"\"linetype\":\"disp\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"hjust\":0.0,\n",
"\"direction\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"48\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(ggplot(df2.toMap()) { y=\"mpg\"; label=\"model\" } + geomPoint(x=1, color=\"red\") + xlim(0.9 to 1.3) + ylim(19 to 35)\n",
" + geomTextRepel(x=1, nudgeX=0.2, direction=\"y\", hjust=0.0, seed=seed) { linetype=\"disp\" })\n",
" .show()"
]
},
{
"cell_type": "markdown",
"id": "5a951ee9-2752-4aa2-b206-7bc9d9980e03",
"metadata": {},
"source": [
"### `arrow` parameter"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "0af8fccd-a08a-4125-b258-8a45b442b48f",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T16:05:05.684275Z",
"iopub.status.busy": "2025-12-03T16:05:05.684081Z",
"iopub.status.idle": "2025-12-03T16:05:05.743718Z",
"shell.execute_reply": "2025-12-03T16:05:05.743523Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" <div id=\"Y4rXcV\" ></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" \n",
" (function() {\n",
" // ----------\n",
" \n",
" const forceImmediateRender = false;\n",
" const responsive = false;\n",
" \n",
" let sizing = {\n",
" width_mode: \"MIN\",\n",
" height_mode: \"SCALED\",\n",
" width: null, \n",
" height: null \n",
" };\n",
" \n",
" const preferredWidth = document.body.dataset.letsPlotPreferredWidth;\n",
" if (preferredWidth !== undefined) {\n",
" sizing = {\n",
" width_mode: 'FIXED',\n",
" height_mode: 'SCALED',\n",
" width: parseFloat(preferredWidth)\n",
" };\n",
" }\n",
" \n",
" const containerDiv = document.getElementById(\"Y4rXcV\");\n",
" let fig = null;\n",
" \n",
" function renderPlot() {\n",
" if (fig === null) {\n",
" const plotSpec = {\n",
"\"mapping\":{\n",
"\"y\":\"mpg\",\n",
"\"label\":\"model\"\n",
"},\n",
"\"data\":{\n",
"\"mpg\":[21.0,21.0,22.8,32.4,21.5,26.0,19.7,21.4],\n",
"\"model\":[\"Mazda RX4\",\"Mazda RX4 Wag\",\"Datsun 710\",\"Fiat 128\",\"Toyota Corona\",\"Porsche 914-2\",\"Ferrari Dino\",\"Volvo 142E\"]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[0.9,1.3]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[19.0,35.0]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"color\":\"red\",\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"point\",\n",
"\"data\":{\n",
"}\n",
"},{\n",
"\"nudge_x\":0.2,\n",
"\"mapping\":{\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"seed\":530.0,\n",
"\"arrow\":{\n",
"\"name\":\"arrow\",\n",
"\"angle\":10.0,\n",
"\"ends\":\"both\",\n",
"\"type\":\"closed\"\n",
"},\n",
"\"x\":1.0,\n",
"\"position\":\"identity\",\n",
"\"geom\":\"text_repel\",\n",
"\"hjust\":0.0,\n",
"\"direction\":\"y\",\n",
"\"data\":{\n",
"}\n",
"}],\n",
"\"data_meta\":{\n",
"\"series_annotations\":[{\n",
"\"type\":\"str\",\n",
"\"column\":\"model\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"mpg\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"cyl\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"disp\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"hp\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"drat\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"wt\"\n",
"},{\n",
"\"type\":\"float\",\n",
"\"column\":\"qsec\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"vs\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"am\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"gear\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"carb\"\n",
"},{\n",
"\"type\":\"int\",\n",
"\"column\":\"shape\"\n",
"}]\n",
"},\n",
"\"spec_id\":\"49\"\n",
"};\n",
" window.letsPlotCall(function() { fig = LetsPlot.buildPlotFromProcessedSpecs(plotSpec, containerDiv, sizing); });\n",
" } else {\n",
" fig.updateView({});\n",
" }\n",
" }\n",
" \n",
" const renderImmediately = \n",
" forceImmediateRender || (\n",
" sizing.width_mode === 'FIXED' && \n",
" (sizing.height_mode === 'FIXED' || sizing.height_mode === 'SCALED')\n",
" );\n",
" \n",
" if (renderImmediately) {\n",
" renderPlot();\n",
" }\n",
" \n",
" if (!renderImmediately || responsive) {\n",
" // Set up observer for initial sizing or continuous monitoring\n",
" var observer = new ResizeObserver(function(entries) {\n",
" for (let entry of entries) {\n",
" if (entry.contentBoxSize && \n",
" entry.contentBoxSize[0].inlineSize > 0) {\n",
" if (!responsive && observer) {\n",
" observer.disconnect();\n",
" observer = null;\n",
" }\n",
" renderPlot();\n",
" if (!responsive) {\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" });\n",
" \n",
" observer.observe(containerDiv);\n",
" }\n",
" \n",
" // ----------\n",
" })();\n",
" \n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(ggplot(df2.toMap()) { y=\"mpg\"; label=\"model\" }\n",
" + geomPoint(x=1, color=\"red\")\n",
" + geomTextRepel(\n",
" x = 1,\n",
" nudgeX = 0.2,\n",
" direction = \"y\",\n",
" hjust = 0.0,\n",
" arrow = arrow(type = \"closed\", angle = 10, ends = \"both\"),\n",
" seed = seed\n",
" )\n",
" + xlim(0.9 to 1.3)\n",
" + ylim(19 to 35)\n",
" ).show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"codemirror_mode": "text/x-kotlin",
"file_extension": ".kt",
"mimetype": "text/x-kotlin",
"name": "kotlin",
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "2.2.20-Beta2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}