{ "cells": [ { "cell_type": "markdown", "id": "872680a6", "metadata": {}, "source": [ "# Lines in Lets-Plot" ] }, { "cell_type": "code", "execution_count": 1, "id": "9c24c1d2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
DataFrame: rowsCount = 5, columnsCount = 12
\n", " \n", " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpgDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv\")\n", "mpgDf.head()\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "f395c360", "metadata": {}, "outputs": [], "source": [ "val mpgMap = mpgDf.toMap()" ] }, { "cell_type": "code", "execution_count": 5, "id": "781fdc93", "metadata": {}, "outputs": [], "source": [ "val regModel = (mpgMap[\"cty\"]!! zip mpgMap[\"hwy\"]!!).simpleRegression(\n", " xSelector = { it.first as Number },\n", " ySelector = { it.second as Number }\n", ")\n", "val ctyMedian = mpgDf.cty.median()\n", "val hwyMedian = mpgDf.hwy.median()" ] }, { "cell_type": "code", "execution_count": 6, "id": "ac17c9ed", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(mpgMap) { x = \"cty\"; y = \"hwy\" } +\n", " geomPoint() +\n", " geomVLine(xintercept = ctyMedian, color = \"#756bb1\", linetype = \"dashed\") +\n", " geomHLine(yintercept = hwyMedian, color = \"#756bb1\", linetype = \"dashed\") +\n", " geomABLine(slope = regModel.slope, intercept = regModel.intercept, color = \"#de2d26\") +\n", " themeMinimal()" ] }, { "cell_type": "markdown", "id": "4211165f", "metadata": {}, "source": [ "## Broken lines" ] }, { "cell_type": "code", "execution_count": 7, "id": "d1c840c9", "metadata": {}, "outputs": [], "source": [ "fun generateParabolicDataMap(n: Int = 25, a: Double = 1.0): Map