%useLatestDescriptors
%use lets-plot
//%use krangl
LetsPlot.getInfo() // Work around Krangl loading old Lets-Plot classes.
Lets-Plot Kotlin API v.4.1.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.2.5.1.
%use krangl
val df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
df.head(3)
manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
Shape: 3 x 12.
val p = letsPlot(df.toMap()) { x = "cty"; y = "hwy"; color = "drv" } +
geomPoint(tooltips = layerTooltips()
.title("@manufacturer @model")
.line("@|@class")
.line("@|@year")) +
labs(
title = "The plot title",
subtitle = "The plot subtitle",
caption = "The plot caption",
color = "Drive type"
)
p
// Font size and face.
val p1 = p + theme(
title = elementText(size=18),
plotTitle = elementText(face="bold"),
plotCaption = elementText(size=12, face="italic"),
axisText = elementText(size=14, face="italic"),
tooltipText = elementText(size=15)
)
p1
// Font family.
p1 + theme(text = elementText(family="Times New Roman"))