Skip to content

JetBrains/lets-plot-kotlin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lets-Plot for Kotlin official JetBrains project

Latest Lets-Plot Kotlin API Version
Latest Lets-Plot Version
License

Lets-Plot for Kotlin is a Kotlin API for the Lets-Plot library - a multiplatform plotting library,
which is built on the principles of layered graphics first described in the Leland Wilkinson work The Grammar of Graphics.

book cover

Lets-Plot Kotlin API is largely based on the API
provided by ggplot2 package well-known to data scientists who use R.

To learn more about the Grammar of Graphics,
we recommend an excellent book called
“ggplot2: Elegant Graphics for Data Analysis”.

This will be a good prerequisite for further exploration of the Lets-Plot library.

Quickstart

Inside Kotlin Notebook, Datalore or Jupyter with Kotlin Kernel:

%use lets-plot
val rand = java.util.Random()
val data = mapOf(
    "rating" to List(200) { rand.nextGaussian() } + List(200) { rand.nextGaussian() * 1.5 + 1.5 },
    "cond" to List(200) { "A" } + List(200) { "B" }
)

var p = letsPlot(data)
p += geomDensity(color = "dark_green", alpha = .3) { x = "rating"; fill = "cond" }
p + ggsize(700, 350)

Couldn't load quickstart_notebook.png


See the "Quickstart" notebook in Datalore or Jupyter nbviewer.

Table of Contents

Lets-Plot in Notebook

"Line Magics"

Include all the necessary Lets-Plot boilerplate code to a notebook using the following "line magic":

%use lets-plot

This will apply the lets-plot library descriptor bundled with the Kotlin Jupyter Kernel installed in your environment.

The %useLatestDescriptors line magic will force Kotlin Kernel to pull and apply all the latest library descriptors from the Kotlin Jupyter Libraries repository.

You can override lets-plot library descriptor settings using the lets-plot line magic parameters:

%use lets-plot(api=1.1.0, lib=1.5.4, js=1.5.4, isolatedFrame=false)
  • api - the version of Lets-Plot Kotlin API.
  • lib - the version of Lets-Plot library (JAR-s).
  • js - the version of Lets-PLot JavaScript bundle.
  • isolatedFrame - If false: load JS just once per notebook (default in Jupyter). If true: include Lets-Plot JS in each output (default in Datalore notebooks).

Lets-Plot in JVM and Kotlin/JS Application

To learn more about creating plots in JVM or Kotlin/JS environment read LPK_APP.md.

In the lets-plot-mini-apps GitHub repository you will find examples of using Lets-Plot Kotlin API in JVM and Kotlin/JS projects.

Documentation

What is new in 4.4.2

Note: Due to major package refactoring in the main Lets-Plot library, this version (4.4.2) of the Kotlin API
is not compatible with versions of Lets-Plot library v3.2.0 and earlier.

A Number of Geometry Defaults Changed

  • The default qualitative color palette is now Color Brewer "Set1" (was "Set2").
  • Slightly bigger default size of points and width of lines.
  • Flavor-aware default colors for points, lines etc.
    f-23c/images/geom_defaults.png
    f-23c/images/flavor_geom_colors.png

See: example notebook.

  • Size of points is slightly adjusted to match the width of a line of the same "size".
    f-23c/images/point_vs_line.png

Support for Variadic Line Width and/or Color in geomLine() and geomPath()


f-23c/images/variadic_width.png

See: example notebook.

Parameter "sizeUnit" in geomPie()

A way to specify size of the pie in units relative to the plot size.

See: example notebook.

Stroke and Spacers in geomPie()


f-23c/images/pie_stroke.png

See: example notebook.

New themeVoid(), Geometries and Statistics

Other improvements and fixes

See CHANGELOG.md for details.

Migrating from v3 to v4

For migration instructions see Migrating to 4.0.0 section in the CHANGELOG.

Change Log

See CHANGELOG.md.

Code of Conduct

This project and the corresponding community are governed by the JetBrains Open Source and Community Code of Conduct. Please make sure you read it.

License

Code and documentation released under the MIT license. Copyright © 2019-2023, JetBrains s.r.o.