{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "fiscal-holly", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"0IKdgH\"></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.0.0/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(\"0IKdgH\").appendChild(div);\n", " };\n", " var e = document.getElementById(\"0IKdgH\");\n", " e.appendChild(script);\n", " })();\n", " </script>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " <div id=\"kotlin_out_0\"/>\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", "}\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" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "worthy-cedar", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "weird-republican", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":3,\"ncol\":12,\"columns\":[\"untitled\",\"manufacturer\",\"model\",\"displ\",\"year\",\"cyl\",\"trans\",\"drv\",\"cty\",\"hwy\",\"fl\",\"class\"],\"kotlin_dataframe\":[{\"untitled\":1,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"auto(l5)\",\"drv\":\"f\",\"cty\":18,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":2,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":1.8,\"year\":1999,\"cyl\":4,\"trans\":\"manual(m5)\",\"drv\":\"f\",\"cty\":21,\"hwy\":29,\"fl\":\"p\",\"class\":\"compact\"},{\"untitled\":3,\"manufacturer\":\"audi\",\"model\":\"a4\",\"displ\":2.0,\"year\":2008,\"cyl\":4,\"trans\":\"manual(m6)\",\"drv\":\"f\",\"cty\":20,\"hwy\":31,\"fl\":\"p\",\"class\":\"compact\"}]}", "text/html": [ " <html>\n", " <head>\n", " <style type=\"text/css\">\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", "}\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", "\n", "\n", " </style>\n", " </head>\n", " <body>\n", " \n", "<table class=\"dataframe\" id=\"df_-1426063360\"></table>\n", "\n", "<p class=\"dataframe_description\">DataFrame: rowsCount = 3, columnsCount = 12</p>\n", " </body>\n", " <script>\n", " \n", "/*<!--*/\n", "call_DataFrame(function() { DataFrame.addTable({ cols: [{ name: \"<span title=\\\"untitled: Int\\\">untitled</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">3</span></span>\"] }, \n", "{ name: \"<span title=\\\"manufacturer: String\\\">manufacturer</span>\", children: [], rightAlign: false, values: [\"audi\",\"audi\",\"audi\"] }, \n", "{ name: \"<span title=\\\"model: String\\\">model</span>\", children: [], rightAlign: false, values: [\"a4\",\"a4\",\"a4\"] }, \n", "{ name: \"<span title=\\\"displ: Double\\\">displ</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1.8</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1.8</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2.0</span></span>\"] }, \n", "{ name: \"<span title=\\\"year: Int\\\">year</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1999</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">1999</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">2008</span></span>\"] }, \n", "{ name: \"<span title=\\\"cyl: Int\\\">cyl</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">4</span></span>\"] }, \n", "{ name: \"<span title=\\\"trans: String\\\">trans</span>\", children: [], rightAlign: false, values: [\"auto(l5)\",\"manual(m5)\",\"manual(m6)\"] }, \n", "{ name: \"<span title=\\\"drv: String\\\">drv</span>\", children: [], rightAlign: false, values: [\"f\",\"f\",\"f\"] }, \n", "{ name: \"<span title=\\\"cty: Int\\\">cty</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">18</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">21</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">20</span></span>\"] }, \n", "{ name: \"<span title=\\\"hwy: Int\\\">hwy</span>\", children: [], rightAlign: true, values: [\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">29</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">29</span></span>\",\"<span class=\\\"formatted\\\" title=\\\"\\\"><span class=\\\"numbers\\\">31</span></span>\"] }, \n", "{ name: \"<span title=\\\"fl: String\\\">fl</span>\", children: [], rightAlign: false, values: [\"p\",\"p\",\"p\"] }, \n", "{ name: \"<span title=\\\"class: String\\\">class</span>\", children: [], rightAlign: false, values: [\"compact\",\"compact\",\"compact\"] }, \n", "], id: -1426063360, rootId: -1426063360, totalRows: 3 } ) });\n", "/*-->*/\n", "\n", "call_DataFrame(function() { DataFrame.renderTable(-1426063360) });\n", "\n", "\n", " </script>\n", " </html>" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val df = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv\")\n", "df.head(3)\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "accepted-afternoon", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"jQBxFC\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"ggtitle\":{\n", "\"text\":\"Fuel efficiency\\nfor most popular models of car\",\n", "\"subtitle\":\"Period 1999-2008\"\n", "},\n", "\"mapping\":{\n", "\"x\":\"displ\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "\"displ\":[1.8,1.8,2.0,2.0,2.8,2.8,3.1,1.8,1.8,2.0,2.0,2.8,2.8,3.1,3.1,2.8,3.1,4.2,5.3,5.3,5.3,5.7,6.0,5.7,5.7,6.2,6.2,7.0,5.3,5.3,5.7,6.5,2.4,2.4,3.1,3.5,3.6,2.4,3.0,3.3,3.3,3.3,3.3,3.3,3.8,3.8,3.8,4.0,3.7,3.7,3.9,3.9,4.7,4.7,4.7,5.2,5.2,3.9,4.7,4.7,4.7,5.2,5.7,5.9,4.7,4.7,4.7,4.7,4.7,4.7,5.2,5.2,5.7,5.9,4.6,5.4,5.4,4.0,4.0,4.0,4.0,4.6,5.0,4.2,4.2,4.6,4.6,4.6,5.4,5.4,3.8,3.8,4.0,4.0,4.6,4.6,4.6,4.6,5.4,1.6,1.6,1.6,1.6,1.6,1.8,1.8,1.8,2.0,2.4,2.4,2.4,2.4,2.5,2.5,3.3,2.0,2.0,2.0,2.0,2.7,2.7,2.7,3.0,3.7,4.0,4.7,4.7,4.7,5.7,6.1,4.0,4.2,4.4,4.6,5.4,5.4,5.4,4.0,4.0,4.6,5.0,2.4,2.4,2.5,2.5,3.5,3.5,3.0,3.0,3.5,3.3,3.3,4.0,5.6,3.1,3.8,3.8,3.8,5.3,2.5,2.5,2.5,2.5,2.5,2.5,2.2,2.2,2.5,2.5,2.5,2.5,2.5,2.5,2.7,2.7,3.4,3.4,4.0,4.7,2.2,2.2,2.4,2.4,3.0,3.0,3.5,2.2,2.2,2.4,2.4,3.0,3.0,3.3,1.8,1.8,1.8,1.8,1.8,4.7,5.7,2.7,2.7,2.7,3.4,3.4,4.0,4.0,2.0,2.0,2.0,2.0,2.8,1.9,2.0,2.0,2.0,2.0,2.5,2.5,2.8,2.8,1.9,1.9,2.0,2.0,2.5,2.5,1.8,1.8,2.0,2.0,2.8,2.8,3.6],\n", "\"hwy\":[29.0,29.0,31.0,30.0,26.0,26.0,27.0,26.0,25.0,28.0,27.0,25.0,25.0,25.0,25.0,24.0,25.0,23.0,20.0,15.0,20.0,17.0,17.0,26.0,23.0,26.0,25.0,24.0,19.0,14.0,15.0,17.0,27.0,30.0,26.0,29.0,26.0,24.0,24.0,22.0,22.0,24.0,24.0,17.0,22.0,21.0,23.0,23.0,19.0,18.0,17.0,17.0,19.0,19.0,12.0,17.0,15.0,17.0,17.0,12.0,17.0,16.0,18.0,15.0,16.0,12.0,17.0,17.0,16.0,12.0,15.0,16.0,17.0,15.0,17.0,17.0,18.0,17.0,19.0,17.0,19.0,19.0,17.0,17.0,17.0,16.0,16.0,17.0,15.0,17.0,26.0,25.0,26.0,24.0,21.0,22.0,23.0,22.0,20.0,33.0,32.0,32.0,29.0,32.0,34.0,36.0,36.0,29.0,26.0,27.0,30.0,31.0,26.0,26.0,28.0,26.0,29.0,28.0,27.0,24.0,24.0,24.0,22.0,19.0,20.0,17.0,12.0,19.0,18.0,14.0,15.0,18.0,18.0,15.0,17.0,16.0,18.0,17.0,19.0,19.0,17.0,29.0,27.0,31.0,32.0,27.0,26.0,26.0,25.0,25.0,17.0,17.0,20.0,18.0,26.0,26.0,27.0,28.0,25.0,25.0,24.0,27.0,25.0,26.0,23.0,26.0,26.0,26.0,26.0,25.0,27.0,25.0,27.0,20.0,20.0,19.0,17.0,20.0,17.0,29.0,27.0,31.0,31.0,26.0,26.0,28.0,27.0,29.0,31.0,31.0,26.0,26.0,27.0,30.0,33.0,35.0,37.0,35.0,15.0,18.0,20.0,20.0,22.0,17.0,19.0,18.0,20.0,29.0,26.0,29.0,29.0,24.0,44.0,29.0,26.0,29.0,29.0,29.0,29.0,23.0,24.0,44.0,41.0,29.0,26.0,28.0,29.0,29.0,29.0,28.0,29.0,26.0,26.0,26.0]\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[{\n", "\"aesthetic\":\"x\",\n", "\"name\":\"Engine displacement\\n(litres)\"\n", "},{\n", "\"aesthetic\":\"y\",\n", "\"name\":\"Highway\\nmiles per gallon\"\n", "}],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"identity\",\n", "\"position\":\"identity\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "}\n", "}],\n", "\"caption\":{\n", "\"text\":\"MPG Dataset\"\n", "},\n", "\"theme\":{\n", "\"name\":\"classic\",\n", "\"plot_background\":{\n", "\"size\":1.0,\n", "\"blank\":false\n", "}\n", "}\n", "};\n", " var plotContainer = document.getElementById(\"jQBxFC\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(df.toMap()) { x = \"displ\"; y = \"hwy\" } + geomPoint() +\n", " labs(\n", " title = \"Fuel efficiency\\nfor most popular models of car\",\n", " subtitle = \"Period 1999-2008\",\n", " caption = \"MPG Dataset\",\n", " x = \"Engine displacement\\n(litres)\", \n", " y = \"Highway\\nmiles per gallon\"\n", " ) + themeClassic() + theme(plotBackground = elementRect(size=1))\n", "p" ] }, { "cell_type": "code", "execution_count": 5, "id": "posted-newsletter", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"FA1eXe\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"ggtitle\":{\n", "\"text\":\"Fuel efficiency\\nfor most popular models of car\",\n", "\"subtitle\":\"Period 1999-2008\"\n", "},\n", "\"mapping\":{\n", "\"x\":\"displ\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "\"displ\":[1.8,1.8,2.0,2.0,2.8,2.8,3.1,1.8,1.8,2.0,2.0,2.8,2.8,3.1,3.1,2.8,3.1,4.2,5.3,5.3,5.3,5.7,6.0,5.7,5.7,6.2,6.2,7.0,5.3,5.3,5.7,6.5,2.4,2.4,3.1,3.5,3.6,2.4,3.0,3.3,3.3,3.3,3.3,3.3,3.8,3.8,3.8,4.0,3.7,3.7,3.9,3.9,4.7,4.7,4.7,5.2,5.2,3.9,4.7,4.7,4.7,5.2,5.7,5.9,4.7,4.7,4.7,4.7,4.7,4.7,5.2,5.2,5.7,5.9,4.6,5.4,5.4,4.0,4.0,4.0,4.0,4.6,5.0,4.2,4.2,4.6,4.6,4.6,5.4,5.4,3.8,3.8,4.0,4.0,4.6,4.6,4.6,4.6,5.4,1.6,1.6,1.6,1.6,1.6,1.8,1.8,1.8,2.0,2.4,2.4,2.4,2.4,2.5,2.5,3.3,2.0,2.0,2.0,2.0,2.7,2.7,2.7,3.0,3.7,4.0,4.7,4.7,4.7,5.7,6.1,4.0,4.2,4.4,4.6,5.4,5.4,5.4,4.0,4.0,4.6,5.0,2.4,2.4,2.5,2.5,3.5,3.5,3.0,3.0,3.5,3.3,3.3,4.0,5.6,3.1,3.8,3.8,3.8,5.3,2.5,2.5,2.5,2.5,2.5,2.5,2.2,2.2,2.5,2.5,2.5,2.5,2.5,2.5,2.7,2.7,3.4,3.4,4.0,4.7,2.2,2.2,2.4,2.4,3.0,3.0,3.5,2.2,2.2,2.4,2.4,3.0,3.0,3.3,1.8,1.8,1.8,1.8,1.8,4.7,5.7,2.7,2.7,2.7,3.4,3.4,4.0,4.0,2.0,2.0,2.0,2.0,2.8,1.9,2.0,2.0,2.0,2.0,2.5,2.5,2.8,2.8,1.9,1.9,2.0,2.0,2.5,2.5,1.8,1.8,2.0,2.0,2.8,2.8,3.6],\n", "\"hwy\":[29.0,29.0,31.0,30.0,26.0,26.0,27.0,26.0,25.0,28.0,27.0,25.0,25.0,25.0,25.0,24.0,25.0,23.0,20.0,15.0,20.0,17.0,17.0,26.0,23.0,26.0,25.0,24.0,19.0,14.0,15.0,17.0,27.0,30.0,26.0,29.0,26.0,24.0,24.0,22.0,22.0,24.0,24.0,17.0,22.0,21.0,23.0,23.0,19.0,18.0,17.0,17.0,19.0,19.0,12.0,17.0,15.0,17.0,17.0,12.0,17.0,16.0,18.0,15.0,16.0,12.0,17.0,17.0,16.0,12.0,15.0,16.0,17.0,15.0,17.0,17.0,18.0,17.0,19.0,17.0,19.0,19.0,17.0,17.0,17.0,16.0,16.0,17.0,15.0,17.0,26.0,25.0,26.0,24.0,21.0,22.0,23.0,22.0,20.0,33.0,32.0,32.0,29.0,32.0,34.0,36.0,36.0,29.0,26.0,27.0,30.0,31.0,26.0,26.0,28.0,26.0,29.0,28.0,27.0,24.0,24.0,24.0,22.0,19.0,20.0,17.0,12.0,19.0,18.0,14.0,15.0,18.0,18.0,15.0,17.0,16.0,18.0,17.0,19.0,19.0,17.0,29.0,27.0,31.0,32.0,27.0,26.0,26.0,25.0,25.0,17.0,17.0,20.0,18.0,26.0,26.0,27.0,28.0,25.0,25.0,24.0,27.0,25.0,26.0,23.0,26.0,26.0,26.0,26.0,25.0,27.0,25.0,27.0,20.0,20.0,19.0,17.0,20.0,17.0,29.0,27.0,31.0,31.0,26.0,26.0,28.0,27.0,29.0,31.0,31.0,26.0,26.0,27.0,30.0,33.0,35.0,37.0,35.0,15.0,18.0,20.0,20.0,22.0,17.0,19.0,18.0,20.0,29.0,26.0,29.0,29.0,24.0,44.0,29.0,26.0,29.0,29.0,29.0,29.0,23.0,24.0,44.0,41.0,29.0,26.0,28.0,29.0,29.0,29.0,28.0,29.0,26.0,26.0,26.0]\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[{\n", "\"aesthetic\":\"x\",\n", "\"name\":\"Engine displacement\\n(litres)\"\n", "},{\n", "\"aesthetic\":\"y\",\n", "\"name\":\"Highway\\nmiles per gallon\"\n", "}],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"identity\",\n", "\"position\":\"identity\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "}\n", "}],\n", "\"caption\":{\n", "\"text\":\"MPG Dataset\"\n", "},\n", "\"theme\":{\n", "\"name\":\"classic\",\n", "\"plot_background\":{\n", "\"size\":1.0,\n", "\"blank\":false\n", "},\n", "\"axis_title_y\":{\n", "\"margin\":{\n", "\"r\":10.0,\n", "\"l\":15.0\n", "},\n", "\"blank\":false\n", "},\n", "\"plot_title\":{\n", "\"margin\":{\n", "\"t\":15.0\n", "},\n", "\"blank\":false\n", "},\n", "\"plot_caption\":{\n", "\"margin\":{\n", "\"b\":15.0\n", "},\n", "\"blank\":false\n", "},\n", "\"axis_title_x\":{\n", "\"margin\":{\n", "\"t\":10.0\n", "},\n", "\"blank\":false\n", "},\n", "\"plot_subtitle\":{\n", "\"margin\":{\n", "\"b\":10.0\n", "},\n", "\"blank\":false\n", "}\n", "}\n", "};\n", " var plotContainer = document.getElementById(\"FA1eXe\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Change margins around plot title, subtitle, caption and axis titles\n", "\n", "p + theme(plotTitle = elementText(margin = margin(t=15)), \n", " plotSubtitle = elementText(margin = margin(b=10)),\n", " plotCaption = elementText(margin = margin(b=15)),\n", " axisTitleX = elementText(margin = margin(t=10)), \n", " axisTitleY = elementText(margin = margin(r=10, l=15)))" ] }, { "cell_type": "code", "execution_count": 6, "id": "median-badge", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"sqxyn8\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"ggtitle\":{\n", "\"text\":\"Fuel efficiency\\nfor most popular models of car\",\n", "\"subtitle\":\"Period 1999-2008\"\n", "},\n", "\"mapping\":{\n", "\"x\":\"displ\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "\"displ\":[1.8,1.8,2.0,2.0,2.8,2.8,3.1,1.8,1.8,2.0,2.0,2.8,2.8,3.1,3.1,2.8,3.1,4.2,5.3,5.3,5.3,5.7,6.0,5.7,5.7,6.2,6.2,7.0,5.3,5.3,5.7,6.5,2.4,2.4,3.1,3.5,3.6,2.4,3.0,3.3,3.3,3.3,3.3,3.3,3.8,3.8,3.8,4.0,3.7,3.7,3.9,3.9,4.7,4.7,4.7,5.2,5.2,3.9,4.7,4.7,4.7,5.2,5.7,5.9,4.7,4.7,4.7,4.7,4.7,4.7,5.2,5.2,5.7,5.9,4.6,5.4,5.4,4.0,4.0,4.0,4.0,4.6,5.0,4.2,4.2,4.6,4.6,4.6,5.4,5.4,3.8,3.8,4.0,4.0,4.6,4.6,4.6,4.6,5.4,1.6,1.6,1.6,1.6,1.6,1.8,1.8,1.8,2.0,2.4,2.4,2.4,2.4,2.5,2.5,3.3,2.0,2.0,2.0,2.0,2.7,2.7,2.7,3.0,3.7,4.0,4.7,4.7,4.7,5.7,6.1,4.0,4.2,4.4,4.6,5.4,5.4,5.4,4.0,4.0,4.6,5.0,2.4,2.4,2.5,2.5,3.5,3.5,3.0,3.0,3.5,3.3,3.3,4.0,5.6,3.1,3.8,3.8,3.8,5.3,2.5,2.5,2.5,2.5,2.5,2.5,2.2,2.2,2.5,2.5,2.5,2.5,2.5,2.5,2.7,2.7,3.4,3.4,4.0,4.7,2.2,2.2,2.4,2.4,3.0,3.0,3.5,2.2,2.2,2.4,2.4,3.0,3.0,3.3,1.8,1.8,1.8,1.8,1.8,4.7,5.7,2.7,2.7,2.7,3.4,3.4,4.0,4.0,2.0,2.0,2.0,2.0,2.8,1.9,2.0,2.0,2.0,2.0,2.5,2.5,2.8,2.8,1.9,1.9,2.0,2.0,2.5,2.5,1.8,1.8,2.0,2.0,2.8,2.8,3.6],\n", "\"hwy\":[29.0,29.0,31.0,30.0,26.0,26.0,27.0,26.0,25.0,28.0,27.0,25.0,25.0,25.0,25.0,24.0,25.0,23.0,20.0,15.0,20.0,17.0,17.0,26.0,23.0,26.0,25.0,24.0,19.0,14.0,15.0,17.0,27.0,30.0,26.0,29.0,26.0,24.0,24.0,22.0,22.0,24.0,24.0,17.0,22.0,21.0,23.0,23.0,19.0,18.0,17.0,17.0,19.0,19.0,12.0,17.0,15.0,17.0,17.0,12.0,17.0,16.0,18.0,15.0,16.0,12.0,17.0,17.0,16.0,12.0,15.0,16.0,17.0,15.0,17.0,17.0,18.0,17.0,19.0,17.0,19.0,19.0,17.0,17.0,17.0,16.0,16.0,17.0,15.0,17.0,26.0,25.0,26.0,24.0,21.0,22.0,23.0,22.0,20.0,33.0,32.0,32.0,29.0,32.0,34.0,36.0,36.0,29.0,26.0,27.0,30.0,31.0,26.0,26.0,28.0,26.0,29.0,28.0,27.0,24.0,24.0,24.0,22.0,19.0,20.0,17.0,12.0,19.0,18.0,14.0,15.0,18.0,18.0,15.0,17.0,16.0,18.0,17.0,19.0,19.0,17.0,29.0,27.0,31.0,32.0,27.0,26.0,26.0,25.0,25.0,17.0,17.0,20.0,18.0,26.0,26.0,27.0,28.0,25.0,25.0,24.0,27.0,25.0,26.0,23.0,26.0,26.0,26.0,26.0,25.0,27.0,25.0,27.0,20.0,20.0,19.0,17.0,20.0,17.0,29.0,27.0,31.0,31.0,26.0,26.0,28.0,27.0,29.0,31.0,31.0,26.0,26.0,27.0,30.0,33.0,35.0,37.0,35.0,15.0,18.0,20.0,20.0,22.0,17.0,19.0,18.0,20.0,29.0,26.0,29.0,29.0,24.0,44.0,29.0,26.0,29.0,29.0,29.0,29.0,23.0,24.0,44.0,41.0,29.0,26.0,28.0,29.0,29.0,29.0,28.0,29.0,26.0,26.0,26.0]\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[{\n", "\"aesthetic\":\"x\",\n", "\"name\":\"Engine displacement\\n(litres)\"\n", "},{\n", "\"aesthetic\":\"y\",\n", "\"name\":\"Highway\\nmiles per gallon\"\n", "}],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"identity\",\n", "\"position\":\"identity\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "}\n", "}],\n", "\"caption\":{\n", "\"text\":\"MPG Dataset\"\n", "},\n", "\"theme\":{\n", "\"name\":\"classic\",\n", "\"plot_background\":{\n", "\"size\":1.0,\n", "\"blank\":false\n", "},\n", "\"axis_text_y\":{\n", "\"margin\":{\n", "\"r\":10.0,\n", "\"l\":15.0\n", "},\n", "\"blank\":false\n", "},\n", "\"axis_text_x\":{\n", "\"margin\":{\n", "\"t\":10.0,\n", "\"b\":15.0\n", "},\n", "\"blank\":false\n", "}\n", "}\n", "};\n", " var plotContainer = document.getElementById(\"sqxyn8\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Change margins around axis tick labels\n", "\n", "p + theme(axisTextX = elementText(margin = margin(t=10, b=15)), \n", " axisTextY = elementText(margin = margin(r=10, l=15)))" ] }, { "cell_type": "code", "execution_count": 7, "id": "cutting-justice", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"GZ3zwe\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"class\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot\",\n", "\"position\":\"dodge\",\n", "\"geom\":\"boxplot\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,17.5,23.0,17.0,25.0,26.0],\n", "\"..upper..\":[29.0,29.0,19.0,24.0,18.0,26.0,30.5],\n", "\"..ymax..\":[33.0,32.0,22.0,24.0,20.0,26.0,36.0],\n", "\"..lower..\":[26.0,26.0,17.0,22.0,16.0,24.0,24.5],\n", "\"..ymin..\":[23.0,23.0,14.0,21.0,15.0,23.0,20.0],\n", "\"class\":[\"compact\",\"midsize\",\"suv\",\"minivan\",\"pickup\",\"2seater\",\"subcompact\"]\n", "}\n", "},{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot_outlier\",\n", "\"show_legend\":false,\n", "\"position\":\"dodge\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,27.0,27.0,27.0,17.5,17.5,17.5,17.5,17.5,17.5,17.5,17.5,23.0,17.0,17.0,17.0,17.0,25.0,26.0,26.0],\n", "\"..upper..\":[29.0,29.0,29.0,29.0,29.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,24.0,18.0,18.0,18.0,18.0,26.0,30.5,30.5],\n", "\"..ymax..\":[33.0,33.0,33.0,33.0,32.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,24.0,20.0,20.0,20.0,20.0,26.0,36.0,36.0],\n", "\"..lower..\":[26.0,26.0,26.0,26.0,26.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,22.0,16.0,16.0,16.0,16.0,24.0,24.5,24.5],\n", "\"..ymin..\":[23.0,23.0,23.0,23.0,23.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,21.0,15.0,15.0,15.0,15.0,23.0,20.0,20.0],\n", "\"hwy\":[35.0,37.0,35.0,44.0,NaN,12.0,12.0,25.0,24.0,27.0,25.0,26.0,23.0,17.0,12.0,12.0,12.0,22.0,NaN,44.0,41.0],\n", "\"class\":[\"compact\",\"compact\",\"compact\",\"compact\",\"midsize\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"minivan\",\"pickup\",\"pickup\",\"pickup\",\"pickup\",\"2seater\",\"subcompact\",\"subcompact\"]\n", "}\n", "}]\n", "};\n", " var plotContainer = document.getElementById(\"GZ3zwe\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// axis labels at different levels\n", "\n", "val p2 = letsPlot(df.toMap()) { x = \"class\"; y = \"hwy\" } + geomBoxplot()\n", "p2" ] }, { "cell_type": "code", "execution_count": 8, "id": "lightweight-detroit", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"4GLhJX\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"class\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot\",\n", "\"position\":\"dodge\",\n", "\"geom\":\"boxplot\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,17.5,23.0,17.0,25.0,26.0],\n", "\"..upper..\":[29.0,29.0,19.0,24.0,18.0,26.0,30.5],\n", "\"..ymax..\":[33.0,32.0,22.0,24.0,20.0,26.0,36.0],\n", "\"..lower..\":[26.0,26.0,17.0,22.0,16.0,24.0,24.5],\n", "\"..ymin..\":[23.0,23.0,14.0,21.0,15.0,23.0,20.0],\n", "\"class\":[\"compact\",\"midsize\",\"suv\",\"minivan\",\"pickup\",\"2seater\",\"subcompact\"]\n", "}\n", "},{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot_outlier\",\n", "\"show_legend\":false,\n", "\"position\":\"dodge\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,27.0,27.0,27.0,17.5,17.5,17.5,17.5,17.5,17.5,17.5,17.5,23.0,17.0,17.0,17.0,17.0,25.0,26.0,26.0],\n", "\"..upper..\":[29.0,29.0,29.0,29.0,29.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,24.0,18.0,18.0,18.0,18.0,26.0,30.5,30.5],\n", "\"..ymax..\":[33.0,33.0,33.0,33.0,32.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,24.0,20.0,20.0,20.0,20.0,26.0,36.0,36.0],\n", "\"..lower..\":[26.0,26.0,26.0,26.0,26.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,22.0,16.0,16.0,16.0,16.0,24.0,24.5,24.5],\n", "\"..ymin..\":[23.0,23.0,23.0,23.0,23.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,21.0,15.0,15.0,15.0,15.0,23.0,20.0,20.0],\n", "\"hwy\":[35.0,37.0,35.0,44.0,NaN,12.0,12.0,25.0,24.0,27.0,25.0,26.0,23.0,17.0,12.0,12.0,12.0,22.0,NaN,44.0,41.0],\n", "\"class\":[\"compact\",\"compact\",\"compact\",\"compact\",\"midsize\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"minivan\",\"pickup\",\"pickup\",\"pickup\",\"pickup\",\"2seater\",\"subcompact\",\"subcompact\"]\n", "}\n", "}],\n", "\"theme\":{\n", "\"axis_text_x\":{\n", "\"margin\":{\n", "\"t\":10.0,\n", "\"b\":10.0\n", "},\n", "\"blank\":false\n", "}\n", "}\n", "};\n", " var plotContainer = document.getElementById(\"4GLhJX\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p2 + theme(axisTextX = elementText(margin = margin(t=10, b=10)))" ] }, { "cell_type": "code", "execution_count": 9, "id": "alleged-effects", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"XewNoV\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"class\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "},\n", "\"ggsize\":{\n", "\"width\":550.0,\n", "\"height\":400.0\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot\",\n", "\"position\":\"dodge\",\n", "\"geom\":\"boxplot\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,17.5,23.0,17.0,25.0,26.0],\n", "\"..upper..\":[29.0,29.0,19.0,24.0,18.0,26.0,30.5],\n", "\"..ymax..\":[33.0,32.0,22.0,24.0,20.0,26.0,36.0],\n", "\"..lower..\":[26.0,26.0,17.0,22.0,16.0,24.0,24.5],\n", "\"..ymin..\":[23.0,23.0,14.0,21.0,15.0,23.0,20.0],\n", "\"class\":[\"compact\",\"midsize\",\"suv\",\"minivan\",\"pickup\",\"2seater\",\"subcompact\"]\n", "}\n", "},{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot_outlier\",\n", "\"show_legend\":false,\n", "\"position\":\"dodge\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,27.0,27.0,27.0,17.5,17.5,17.5,17.5,17.5,17.5,17.5,17.5,23.0,17.0,17.0,17.0,17.0,25.0,26.0,26.0],\n", "\"..upper..\":[29.0,29.0,29.0,29.0,29.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,24.0,18.0,18.0,18.0,18.0,26.0,30.5,30.5],\n", "\"..ymax..\":[33.0,33.0,33.0,33.0,32.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,24.0,20.0,20.0,20.0,20.0,26.0,36.0,36.0],\n", "\"..lower..\":[26.0,26.0,26.0,26.0,26.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,22.0,16.0,16.0,16.0,16.0,24.0,24.5,24.5],\n", "\"..ymin..\":[23.0,23.0,23.0,23.0,23.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,21.0,15.0,15.0,15.0,15.0,23.0,20.0,20.0],\n", "\"hwy\":[35.0,37.0,35.0,44.0,NaN,12.0,12.0,25.0,24.0,27.0,25.0,26.0,23.0,17.0,12.0,12.0,12.0,22.0,NaN,44.0,41.0],\n", "\"class\":[\"compact\",\"compact\",\"compact\",\"compact\",\"midsize\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"minivan\",\"pickup\",\"pickup\",\"pickup\",\"pickup\",\"2seater\",\"subcompact\",\"subcompact\"]\n", "}\n", "}]\n", "};\n", " var plotContainer = document.getElementById(\"XewNoV\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// with rotation\n", "\n", "val p3 = p2 + ggsize(550, 400)\n", "p3" ] }, { "cell_type": "code", "execution_count": 10, "id": "scheduled-identity", "metadata": {}, "outputs": [ { "data": { "text/html": [ " <div id=\"sX03VP\"></div>\n", " <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n", " (function() {\n", " var plotSpec={\n", "\"mapping\":{\n", "\"x\":\"class\",\n", "\"y\":\"hwy\"\n", "},\n", "\"data\":{\n", "},\n", "\"ggsize\":{\n", "\"width\":550.0,\n", "\"height\":400.0\n", "},\n", "\"kind\":\"plot\",\n", "\"scales\":[],\n", "\"layers\":[{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot\",\n", "\"position\":\"dodge\",\n", "\"geom\":\"boxplot\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,17.5,23.0,17.0,25.0,26.0],\n", "\"..upper..\":[29.0,29.0,19.0,24.0,18.0,26.0,30.5],\n", "\"..ymax..\":[33.0,32.0,22.0,24.0,20.0,26.0,36.0],\n", "\"..lower..\":[26.0,26.0,17.0,22.0,16.0,24.0,24.5],\n", "\"..ymin..\":[23.0,23.0,14.0,21.0,15.0,23.0,20.0],\n", "\"class\":[\"compact\",\"midsize\",\"suv\",\"minivan\",\"pickup\",\"2seater\",\"subcompact\"]\n", "}\n", "},{\n", "\"mapping\":{\n", "},\n", "\"stat\":\"boxplot_outlier\",\n", "\"show_legend\":false,\n", "\"position\":\"dodge\",\n", "\"geom\":\"point\",\n", "\"data\":{\n", "\"..middle..\":[27.0,27.0,27.0,27.0,27.0,17.5,17.5,17.5,17.5,17.5,17.5,17.5,17.5,23.0,17.0,17.0,17.0,17.0,25.0,26.0,26.0],\n", "\"..upper..\":[29.0,29.0,29.0,29.0,29.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,19.0,24.0,18.0,18.0,18.0,18.0,26.0,30.5,30.5],\n", "\"..ymax..\":[33.0,33.0,33.0,33.0,32.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,22.0,24.0,20.0,20.0,20.0,20.0,26.0,36.0,36.0],\n", "\"..lower..\":[26.0,26.0,26.0,26.0,26.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,17.0,22.0,16.0,16.0,16.0,16.0,24.0,24.5,24.5],\n", "\"..ymin..\":[23.0,23.0,23.0,23.0,23.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,14.0,21.0,15.0,15.0,15.0,15.0,23.0,20.0,20.0],\n", "\"hwy\":[35.0,37.0,35.0,44.0,NaN,12.0,12.0,25.0,24.0,27.0,25.0,26.0,23.0,17.0,12.0,12.0,12.0,22.0,NaN,44.0,41.0],\n", "\"class\":[\"compact\",\"compact\",\"compact\",\"compact\",\"midsize\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"suv\",\"minivan\",\"pickup\",\"pickup\",\"pickup\",\"pickup\",\"2seater\",\"subcompact\",\"subcompact\"]\n", "}\n", "}],\n", "\"theme\":{\n", "\"axis_text_x\":{\n", "\"margin\":{\n", "\"t\":10.0\n", "},\n", "\"blank\":false\n", "}\n", "}\n", "};\n", " var plotContainer = document.getElementById(\"sX03VP\");\n", " window.letsPlotCall(function() {{\n", " LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n", " }});\n", " })(); \n", " </script>" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p3 + theme(axisTextX = elementText(margin = margin(t=10)))" ] } ], "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": "1.8.20" } }, "nbformat": 4, "nbformat_minor": 5 }