{ "cells": [ { "cell_type": "markdown", "id": "educated-sharp", "metadata": {}, "source": [ "## `Free` scales on faceted plot" ] }, { "cell_type": "code", "execution_count": 1, "id": "greenhouse-boxing", "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": "vocational-wells", "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": "native-process", "metadata": {}, "outputs": [], "source": [ "%use krangl" ] }, { "cell_type": "code", "execution_count": 4, "id": "responsible-delight", "metadata": {}, "outputs": [ { "data": { "text/html": [ "miles per gallon | number of cylinders | engine displacement (cu. inches) | engine horsepower | vehicle weight (lbs.) | time to accelerate (sec.) | model year | origin of car | vehicle name |
---|---|---|---|---|---|---|---|---|
18.0 | 8 | 307.0 | 130 | 3504 | 12.0 | 70 | US | chevrolet chevelle malibu |
15.0 | 8 | 350.0 | 165 | 3693 | 11.5 | 70 | US | buick skylark 320 |
18.0 | 8 | 318.0 | 150 | 3436 | 11.0 | 70 | US | plymouth satellite |
16.0 | 8 | 304.0 | 150 | 3433 | 12.0 | 70 | US | amc rebel sst |
17.0 | 8 | 302.0 | 140 | 3449 | 10.5 | 70 | US | ford torino |
Shape: 5 x 9. \n", "
" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var mpg_df = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg2.csv\")\n", "mpg_df.head()\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "personalized-couple", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(mpg_df.toMap()) { \n", " x=\"engine horsepower\"\n", " y=\"engine displacement (cu. inches)\"\n", "} + geomPoint {color=\"origin of car\"} + themeGrey()\n", "p + ggsize(800, 350)" ] }, { "cell_type": "markdown", "id": "turkish-guard", "metadata": {}, "source": [ "### Faceted plot" ] }, { "cell_type": "code", "execution_count": 6, "id": "inclusive-extreme", "metadata": {}, "outputs": [], "source": [ "val fp = p + ggsize(800, 500)" ] }, { "cell_type": "markdown", "id": "dietary-combat", "metadata": {}, "source": [ "#### `facetGrid()` with `fixed` scales (the default)\n", "\n", "Scales are constant across all panels." ] }, { "cell_type": "code", "execution_count": 7, "id": "systematic-warning", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facetGrid(y=\"origin of car\")" ] }, { "cell_type": "markdown", "id": "plastic-purple", "metadata": {}, "source": [ "#### `facetGrid()` with `free` Y-scales" ] }, { "cell_type": "code", "execution_count": 8, "id": "impaired-terry", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facetGrid(y=\"origin of car\", scales=\"free_y\")" ] }, { "cell_type": "markdown", "id": "elect-singing", "metadata": {}, "source": [ "#### `facetWrap()` with `fixed` scales (the default)\n", "\n", "Scales are constant across all panels." ] }, { "cell_type": "code", "execution_count": 9, "id": "abandoned-moral", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facetWrap(facets=\"number of cylinders\", order=1)" ] }, { "cell_type": "markdown", "id": "coated-channel", "metadata": {}, "source": [ "#### `facetWrap()` with `free` scales along both axis" ] }, { "cell_type": "code", "execution_count": 10, "id": "annoying-danger", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fp + facetWrap(facets=\"number of cylinders\", order=1, scales=\"free\")" ] } ], "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.7.20-dev-1299" } }, "nbformat": 4, "nbformat_minor": 5 }