{ "cells": [ { "cell_type": "markdown", "id": "d9ff8a46-2be6-420c-bfff-df77a7b47587", "metadata": {}, "source": [ "# Horizontal and Vertical Facet Labels\n", "New `theme()` parameters allow to set the style for horizontal and vertical facet labels separately:\n", "\n", "- `stripBackgroundX` and `stripBackgroundY` parameters set the background of horizontal and vertical facet labels respectively, specified with `elementRect()`;\n", "\n", "- `stripTextX` and `stripTextY` - horizontal and vertical facet labels, specified with `elementText()`." ] }, { "cell_type": "code", "execution_count": 1, "id": "2aef6e9b-8f16-4134-a395-d7fa8ea7f3bb", "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", "\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "fad33652-bcfd-41c4-8fe2-670d1651e5ca", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.9.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.5.1." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "a8ecf448-aebe-480d-ae4d-b8f39aed0a5b", "metadata": {}, "outputs": [], "source": [ "val df = dataFrameOf(\"animal_type\", \"animal\", \"weight\", \"diet\")(\n", " \"pet\", \"cat\", 5, \"carnivore\",\n", " \"pet\", \"dog\", 10, \"carnivore\",\n", " \"pet\", \"rabbit\", 2, \"herbivore\",\n", " \"pet\", \"hamster\", 1, \"herbivore\",\n", "\n", " \"farm\", \"cow\", 500, \"herbivore\",\n", " \"farm\", \"pig\", 100, \"carnivore\",\n", " \"farm\", \"horse\", 700, \"herbivore\",\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "id": "7ffdc8df-85dc-4c7b-bdb9-c5734e7f22cc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(df.toMap()) { x = \"animal\"; y = \"weight\" } +\n", " geomBar(stat = Stat.identity) +\n", " facetGrid(x = \"animal_type\", y = \"diet\", scales = \"free\") +\n", " themeBW()\n", "\n", "p" ] }, { "cell_type": "markdown", "id": "c4b03b06-6ddb-45b3-ad4e-8c8cbaad5a4c", "metadata": {}, "source": [ "Change the style for facet labels:" ] }, { "cell_type": "code", "execution_count": 5, "id": "3d27e4d9-f648-4c03-85dc-33979bc4eeb2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(stripTextX = elementText(face = \"bold\"),\n", " stripBackgroundX = elementRect(fill = \"pink\"),\n", " stripTextY = elementText(face = \"italic\"),\n", " stripBackgroundY = elementRect(fill = \"light_blue\"))" ] }, { "cell_type": "markdown", "id": "957baf07-7e3b-4dbb-93c6-3e7858c48e36", "metadata": {}, "source": [ "Hide horizontal facet labels:" ] }, { "cell_type": "code", "execution_count": 6, "id": "57bf5c50-7728-4805-91fb-7dcfd6380b2c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(stripTextX = elementBlank())" ] } ], "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.9.23" } }, "nbformat": 4, "nbformat_minor": 5 }