{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This page is available as an executable or viewable Jupyter Notebook:\n", "

\n", "\n", " \n", "\n", "\n", " \n", "\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "// Create a random density plot and save it in a variable \"p\".\n", "val rand = java.util.Random(123)\n", "val n = 400\n", "val data = mapOf (\n", " \"rating\" to List(n/2) { rand.nextGaussian() } + List(n/2) { rand.nextGaussian() * 1.5 + 1.5 },\n", " \"cond\" to List(n/2) { \"A\" } + List(n/2) { \"B\" }\n", ")\n", "\n", "var p = lets_plot(data) +\n", " geom_density { x = \"rating\"; color = \"cond\" } + ggsize(500, 250) " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import java.io.File" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export PNG to file" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "/Users/Igor/Work_misc/jupyter/lets-plot-kotlin/examples/jupyter-notebooks/lets-plot-images/density.png" ] }, "execution_count": 4, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "ggsave(p, \"density.png\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 5, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "HTML(\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export SVG to file" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "/Users/Igor/Work_misc/jupyter/lets-plot-kotlin/examples/jupyter-notebooks/lets-plot-images/density.svg" ] }, "execution_count": 6, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "ggsave(p, \"density.svg\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " -2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.0\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.1\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.3\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " density\n", " \n", " \n", " \n", " \n", " \n", " \n", " rating\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " cond\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " A\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " B\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "" ] }, "execution_count": 7, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "HTML(File(\"lets-plot-images/density.svg\").readText())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Export HTML to file" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "/Users/Igor/Work_misc/jupyter/lets-plot-kotlin/examples/jupyter-notebooks/lets-plot-images/density.html" ] }, "execution_count": 8, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "ggsave(p, \"density.html\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ " " ] }, "execution_count": 9, "metadata": { "new_classpath": [] }, "output_type": "execute_result" } ], "source": [ "HTML(File(\"lets-plot-images/density.html\").readText())" ] } ], "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", "pygments_lexer": "kotlin", "version": "1.5.0-dev-1206" } }, "nbformat": 4, "nbformat_minor": 4 }