%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 mpg_df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
mpg_df.head()
DataFrame: rowsCount = 5, columnsCount = 12
untitled | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.800000 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.800000 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.000000 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
4 | audi | a4 | 2.000000 | 2008 | 4 | auto(av) | f | 21 | 30 | p | compact |
5 | audi | a4 | 2.800000 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | compact |
val p = letsPlot(mpg_df.toMap()) { x = "cty"; y = "hwy"; color = "drv" } +
geomPoint(tooltips = layerTooltips().line("@manufacturer @model"))
// with facets
val pf = p + facetGrid(y = "drv")
fun themeWithFlavors(
plot: org.jetbrains.letsPlot.intern.Plot,
theme: org.jetbrains.letsPlot.intern.OptionsMap,
themeName: String
): GGBunch {
val (w, h) = 400 to 300
return gggrid(
plots = listOf(
plot + theme + ggtitle(themeName),
plot + theme + ggtitle("flavorDarcula()") + flavorDarcula(),
plot + theme + ggtitle("flavorSolarizedLight()") + flavorSolarizedLight(),
plot + theme + ggtitle("flavorSolarizedDark()") + flavorSolarizedDark(),
plot + theme + ggtitle("flavorHighContrastLight()") + flavorHighContrastLight(),
plot + theme + ggtitle("flavorHighContrastDark()") + flavorHighContrastDark()
),
ncol = 2,
cellWidth = w,
cellHeight = h,
fit = true
)
}
themeWithFlavors(p, themeMinimal2(), "Minimal2")
themeWithFlavors(pf, themeMinimal2(), "Minimal2 + facets")
themeWithFlavors(p, themeMinimal(), "Minimal")
themeWithFlavors(pf, themeMinimal(), "Minimal + facets")
themeWithFlavors(p, themeClassic(), "Classic")
themeWithFlavors(pf, themeClassic(), "Classic+ facets")
themeWithFlavors(p, themeLight(), "Light")
themeWithFlavors(pf, themeLight(), "Light + facets")
themeWithFlavors(p, themeGrey(), "Grey")
themeWithFlavors(pf, themeGrey(), "Grey + facets")
themeWithFlavors(p, themeNone(), "None")
themeWithFlavors(pf, themeNone(), "None + facets")
themeWithFlavors(p, themeBW(), "BW")
themeWithFlavors(pf, themeBW(), "BW + facets")