{ "cells": [ { "cell_type": "markdown", "id": "awful-desktop", "metadata": {}, "source": [ "### Marginal Plots\n", "\n", "A marginal plot is a scatterplot (sometimes a density plot or other bivariate plot) that has histograms, boxplots, or other distribution visualization layers in the margins of the x- and y-axes. \n", "\n", "It allows studying the relationship between 2 numeric variables. \n", "\n", "You can use the `ggmarginal()` function to add marginal layers to a plot." ] }, { "cell_type": "code", "execution_count": 1, "id": "satisfied-grenada", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "tender-tutorial", "metadata": {}, "outputs": [], "source": [ "@file:DependsOn(\"org.apache.commons:commons-math3:3.6.1\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "norman-point", "metadata": {}, "outputs": [], "source": [ "import org.apache.commons.math3.distribution.MultivariateNormalDistribution" ] }, { "cell_type": "code", "execution_count": 4, "id": "mexican-terror", "metadata": {}, "outputs": [], "source": [ "val cov0 : ArrayDataFrame: rowsCount = 3, columnsCount = 12
\n", " \n", " \n", " " ] }, "execution_count": 15, "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": 16, "id": "combined-diagram", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val plotSettings = ggsize(900, 700) +\n", " theme(plotBackground = elementRect(fill = \"#eaeaea\"), \n", " legendBackground = elementRect(fill = \"#eaeaea\"))\n", "\n", "(letsPlot(mpg.toMap()) {x = \"cty\"; y = \"hwy\"; fill = \"manufacturer\"}\n", " + geomPoint( size = 7, shape = 21, alpha = .5, color = \"black\", position=positionJitter())\n", " + ggmarginal(\"tr\", size = 0.3, \n", " layer = geomBoxplot(width=0.5) {\n", " fill = asDiscrete(\"manufacturer\", orderBy = \"..lower..\")\n", " })\n", " + plotSettings) \n", " " ] } ], "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 }