%useLatestDescriptors
%use dataframe
%use lets-plot
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.9.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.5.1.
val iris = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/iris.csv")
iris.head()
DataFrame: rowsCount = 5, columnsCount = 5
sepal_length | sepal_width | petal_length | petal_width | species |
---|---|---|---|---|
5.100000 | 3.500000 | 1.400000 | 0.200000 | setosa |
4.900000 | 3.000000 | 1.400000 | 0.200000 | setosa |
4.700000 | 3.200000 | 1.300000 | 0.200000 | setosa |
4.600000 | 3.100000 | 1.500000 | 0.200000 | setosa |
5.000000 | 3.600000 | 1.400000 | 0.200000 | setosa |
val data = iris.toMap()
In the simplest case, assign x
and y
to create a scatterplot (using geomPoint()
) with marginal histograms (using geomHistogram()
).
jointPlot(data, "petal_length", "petal_width")
Besides the points there are another two types of geoms: tile
and density2D(Filled)
.
jointPlot(data, "petal_length", "petal_width", geom = "tile")
jointPlot(data, "petal_length", "petal_width", colorBy = "species", geom = "density2d")
Use additional parameters for better customization: color
, size
, alpha
, etc.
jointPlot(data, "petal_length", "petal_width", color = "#756bb1", size = 8, alpha = 0.5, se = false)
jointPlot(data, "petal_length", "petal_width", color = "black", marginal = "box:lb:.03,hist:t:.4,hist:r") +
ggmarginal("tr", layer = geomArea(stat = Stat.density(), color = "magenta", fill = "magenta", alpha = 0.1)) +
theme(axisLine = "blank")
jointPlot(data, "petal_length", "petal_width", colorBy = "species", marginal = "hist:tr")
Add any other layer that supports x
and y
aesthetics (e.g. points layer with the geomPoint()
function).
jointPlot(data, "petal_length", "petal_width", geom = "density2df",
color = "#993404", alpha = 0.3, regLine = false) +
geomPoint(size = 5, shape = 21, color = "#993404", fill = "#ffffd4") +
scaleFillGradient(low = "#d95f0e", high = "#fff7bc")