{ "cells": [ { "cell_type": "markdown", "id": "proud-butler", "metadata": {}, "source": [ "### The layer `orientation` property\n", "\n", "Some geoms treat each axis differently and, thus, can thus have two orientations.\n", "\n", "The `orientation` parameter specifies the axis that the layer' stat and geom should run along (x-axis by default). " ] }, { "cell_type": "code", "execution_count": 1, "id": "humanitarian-german", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "// %use krangl" ] }, { "cell_type": "code", "execution_count": 2, "id": "registered-chance", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.1.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.2.5.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo() // This prevents Krangl from loading an obsolete version of Lets-Plot classes." ] }, { "cell_type": "code", "execution_count": 3, "id": "thousand-filter", "metadata": {}, "outputs": [], "source": [ "%use krangl" ] }, { "cell_type": "code", "execution_count": 4, "id": "guilty-indian", "metadata": {}, "outputs": [ { "data": { "text/html": [ "manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
Shape: 3 x 12. \n", "
" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var mpg = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv\")\n", "mpg.head(3)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "ordinary-friend", "metadata": {}, "outputs": [], "source": [ "val base = letsPlot(mpg.toMap()) + ggsize(800, 300)\n", "val manufacturerMapping = asDiscrete(\"manufacturer\", orderBy = \"..count..\")\n", "val hideXLabel = theme(axisTitleX = \"blank\")\n", "val hideYLabel = theme(axisTitleY = \"blank\")" ] }, { "cell_type": "markdown", "id": "pursuant-stamp", "metadata": {}, "source": [ "### geomBar()" ] }, { "cell_type": "code", "execution_count": 6, "id": "cleared-brooklyn", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// orientation \"x\" (default) : \"manufacturer\" is mapped to the x-axis.\n", "\n", "val orientationX = base + geomBar(color = \"white\") {\n", " x = manufacturerMapping\n", " fill = \"class\"\n", "}\n", "orientationX + hideXLabel" ] }, { "cell_type": "code", "execution_count": 7, "id": "experimental-storm", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Same but flipped coordinate system.\n", "\n", "orientationX + coordFlip() + hideXLabel" ] }, { "cell_type": "code", "execution_count": 8, "id": "referenced-cliff", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "// Orientation \"y\".\n", "// The \"manufacturer\" is mapped to the y-axis.\n", "\n", "val baseY = base + hideYLabel\n", "baseY + geomBar(color = \"white\", orientation=\"y\") {\n", " y = manufacturerMapping\n", " fill = \"class\"\n", "}" ] }, { "cell_type": "markdown", "id": "prime-looking", "metadata": {}, "source": [ "### geomBoxplot()" ] }, { "cell_type": "code", "execution_count": 9, "id": "combined-kingston", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "baseY + geomBoxplot(width = 0.7, orientation = \"y\") {\n", " y = \"manufacturer\"\n", " x = \"cty\" \n", "}" ] }, { "cell_type": "markdown", "id": "interpreted-mileage", "metadata": {}, "source": [ "### `geomViolin()`" ] }, { "cell_type": "code", "execution_count": 10, "id": "elementary-dutch", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpg.toMap()) + geomViolin(trim = false, orientation = \"y\") { y=\"drv\"; x = \"cty\"; fill = \"drv\"} +\n", " geomBoxplot(fill = \"white\", alpha = 0.5, width = 0.3, orientation = \"y\") { \n", " y = \"drv\"\n", " x = \"cty\" \n", " }\n", " " ] }, { "cell_type": "markdown", "id": "blond-gallery", "metadata": {}, "source": [ "## Continuous variables" ] }, { "cell_type": "code", "execution_count": 11, "id": "homeless-madagascar", "metadata": {}, "outputs": [], "source": [ "@file:DependsOn(\"org.apache.commons:commons-math3:3.6.1\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "virtual-minimum", "metadata": {}, "outputs": [], "source": [ "import org.apache.commons.math3.distribution.MultivariateNormalDistribution" ] }, { "cell_type": "code", "execution_count": 13, "id": "secret-vaccine", "metadata": {}, "outputs": [], "source": [ "val cov0 : Array