{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "private-kingston", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "DataFrame: rowsCount = 3, columnsCount = 9
\n", " \n", " \n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpg = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 8, "id": "extensive-democrat", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val p = letsPlot(mpg.head(30).toMap()) { \n", " x = \"vehicle weight (lbs.)\"\n", " y = \"miles per gallon\"\n", " label = \"vehicle name\"\n", "}\n", "\n", "p + geomLabel()" ] }, { "cell_type": "code", "execution_count": 9, "id": "intermediate-bridal", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geomLabel(color = \"white\", fontface = \"bold\") {\n", " fill = asDiscrete(\"number of cylinders\", order = 1)\n", "} + ggsize(800,400)" ] }, { "cell_type": "code", "execution_count": 10, "id": "continent-nudist", "metadata": {}, "outputs": [], "source": [ "// Initialize Lets-Plot GeoTools extension. \n", "%use lets-plot-gt(gt=\"[23,)\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "speaking-massage", "metadata": {}, "outputs": [], "source": [ "@file:DependsOn(\"org.geotools:gt-shapefile:[23,)\")\n", "@file:DependsOn(\"org.geotools:gt-cql:[23,)\")\n", "\n", "import org.geotools.data.shapefile.ShapefileDataStoreFactory\n", "import org.geotools.data.simple.SimpleFeatureCollection\n", "import java.net.URL\n", "\n", "import org.geotools.filter.text.cql2.CQL\n", "\n", "\n", "val factory = ShapefileDataStoreFactory()\n", "\n", "val worldFeatures : SimpleFeatureCollection = with(\"naturalearth_lowres\") {\n", " val url = \"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/${this}/${this}.shp\"\n", " factory.createDataStore(URL(url)).featureSource.features\n", "}\n", "val europe = worldFeatures.subCollection(CQL.toFilter(\"continent = 'Europe'\"))\n", "\n", "val cityFeatures : SimpleFeatureCollection = with(\"naturalearth_cities\") {\n", " val url = \"https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/${this}/${this}.shp\"\n", " factory.createDataStore(URL(url)).featureSource.features\n", "}\n", "val cities = cityFeatures.toSpatialDataset()\n" ] }, { "cell_type": "code", "execution_count": 12, "id": "agricultural-deployment", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot() + \n", " geomMap(map = europe.toSpatialDataset(), fill=\"#e5f5e0\") +\n", " geomPoint(data = cities, color = \"#224717\", size = 3) +\n", " geomLabel(data = cities, hjust = 0, vjust = 1, color = \"#224717\") { label = \"name\" } +\n", " coordMap(xlim = -10.5 to 44.0, ylim = 36.0 to 60.5) +\n", " theme(axis=\"blank\", panelGrid=\"blank\")" ] } ], "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 }