{ "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 gallonnumber of cylindersengine displacement (cu. inches)engine horsepowervehicle weight (lbs.)time to accelerate (sec.)model yearorigin of carvehicle name
18.08307.0130350412.070USchevrolet chevelle malibu
15.08350.0165369311.570USbuick skylark 320
18.08318.0150343611.070USplymouth satellite
16.08304.0150343312.070USamc rebel sst
17.08302.0140344910.570USford 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 }