{ "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" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "vocational-wells", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "responsible-delight", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":5,\"ncol\":9,\"columns\":[\"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\"],\"kotlin_dataframe\":[{\"miles per gallon\":18.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":307.0,\"engine horsepower\":130,\"vehicle weight (lbs.)\":3504,\"time to accelerate (sec.)\":12.0,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"chevrolet chevelle malibu\"},{\"miles per gallon\":15.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":350.0,\"engine horsepower\":165,\"vehicle weight (lbs.)\":3693,\"time to accelerate (sec.)\":11.5,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"buick skylark 320\"},{\"miles per gallon\":18.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":318.0,\"engine horsepower\":150,\"vehicle weight (lbs.)\":3436,\"time to accelerate (sec.)\":11.0,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"plymouth satellite\"},{\"miles per gallon\":16.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":304.0,\"engine horsepower\":150,\"vehicle weight (lbs.)\":3433,\"time to accelerate (sec.)\":12.0,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"amc rebel sst\"},{\"miles per gallon\":17.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":302.0,\"engine horsepower\":140,\"vehicle weight (lbs.)\":3449,\"time to accelerate (sec.)\":10.5,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"ford torino\"}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 5, columnsCount = 9

\n", " \n", " \n", " " ] }, "execution_count": 3, "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": 4, "id": "personalized-couple", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "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": 5, "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": 6, "id": "systematic-warning", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "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": 7, "id": "impaired-terry", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "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": 8, "id": "abandoned-moral", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "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": 9, "id": "annoying-danger", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 9, "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.8.20" } }, "nbformat": 4, "nbformat_minor": 5 }