%useLatestDescriptors
%use lets-plot
%use dataframe
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0.
val df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
df.head(3)
DataFrame: rowsCount = 3, columnsCount = 12
val p = letsPlot(df.toMap()) { x = "cty"; y = "hwy"; color = "drv" } + geomPoint() + labs(color="Drive type")
p
// Horizontal justification for plot title, subtitle, caption, legend and axis titles
val hjustLeft = elementText(hjust = 0.0)
val hjustMiddle = elementText(hjust = 0.5)
val hjustRight = elementText(hjust = 1.0)
fun withHJjust(hjust: Map<String, Any>): org.jetbrains.letsPlot.intern.OptionsMap {
return theme(title = hjust, axisTitle = hjust, plotCaption = hjust, legendTitle = hjust)
}
val p2 = p + labs(caption = "The plot caption")
gggrid(
plots = listOf(
p2 + withHJjust(hjustLeft) + ggtitle("All titles with hjust = 0.0"),
p2 + withHJjust(hjustMiddle) + ggtitle("All titles with hjust = 0.5"),
p2 + withHJjust(hjustRight) + ggtitle("All titles with hjust = 1.0"),
),
ncol = 1,
cellWidth = 600,
cellHeight = 400,
fit = true
)
// Vertical justification for legend title
val vjustBottom = elementText(vjust =0.0)
val vjustCenter = elementText(vjust = 0.5)
val vjustTop = elementText(vjust = 1.0)
fun withVJjust(vjust: Map<String, Any>): org.jetbrains.letsPlot.intern.OptionsMap {
return theme(legendTitle = vjust)
}
val p3 = p + theme().legendPositionBottom() + scaleColorDiscrete(guide = guideLegend(ncol = 1))
gggrid(
plots = listOf(
p3 + withVJjust(vjustBottom) + ggtitle("Legend title with vjust = 0.0"),
p3 + withVJjust(vjustCenter) + ggtitle("Legend title with vjust = 0.5"),
p3 + withVJjust(vjustTop) + ggtitle("Legend title with vjust = 1.0"),
),
ncol = 1,
cellWidth = 600,
cellHeight = 400,
fit = true
)