%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.
var mpg = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
mpg.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 |
letsPlot(mpg.toMap()) + geomViolin { y = "hwy" }
geomViolin()
and geomDesity()
¶val densityPlot = letsPlot(mpg.toMap()) +
geomDensity(color="black", alpha=.5) {x="hwy"; fill="drv"} +
facetGrid(x="drv") +
coordFlip() + scaleYContinuous(breaks = emptyList<Any>()) +
ggtitle("geomDensity()")
val violinPlot = letsPlot(mpg.toMap()) +
geomViolin(alpha=0.5) {
x = asDiscrete("drv", order=1)
y = "hwy"
fill = "drv"
} +
ggtitle("geomViolin()")
gggrid(listOf(densityPlot, violinPlot), 2)
drawQuantiles
¶val quantiles = listOf(.25, .5, .75)
letsPlot(mpg.toMap()) { x = "drv"; y = "hwy" } +
geomViolin(quantiles = quantiles, quantileLines = true) +
ggtitle("quantiles=$quantiles")
scale
¶val options = listOf(null, "area", "count", "width")
val plots = List(options.size) { i ->
letsPlot(mpg.toMap()) { x = "drv"; y = "hwy" } +
geomViolin(scale = options[i], quantiles = quantiles, quantileLines = true) +
ggtitle("scale = ${options[i]} ")
}
gggrid(plots, 2, 400, 250)
ydensity
statistic¶val plotBase = letsPlot(mpg.toMap()) { x = "drv"; y = "hwy" }
val plots1 = listOf(
plotBase + geomViolin(quantiles=quantiles, quantileLines=true) + ggtitle("Default"),
plotBase + geomViolin(quantiles=quantiles, quantileLines=true, kernel="epanechikov") +
ggtitle("kernel='epanechikov'"),
plotBase + geomViolin(quantiles=quantiles, quantileLines=true, bw=.1) + ggtitle("bw=0.1"),
plotBase + geomViolin(quantiles=quantiles, quantileLines=true, adjust=2) + ggtitle("adjust=2"),
)
gggrid(plots1, 2, 400, 250)
val plotBase2 = plotBase +
scaleColorBrewer(type="qual", palette="Set1") +
scaleFillBrewer(type="qual", palette="Set1") +
themeGrey()
plotBase2 +
geomViolin(quantiles = quantiles, quantileLines = true, alpha = 0.5, size = 2,
tooltips = layerTooltips().title("^x")
.line("year|@year")
.line("hwy|@hwy")
.line("violinwidth|@..violinwidth..")
.line("density|@..density..").format("@..density..", ".3f")
.line("count|@..count..").format("@..count..", ".3f")
.line("scaled|@..scaled..").format("@..scaled..", ".3f")
) {
color = asDiscrete("year")
fill = asDiscrete("year")
}
plotBase2 +
geomViolin(quantiles = quantiles, quantileLines = true, alpha = 0.5, size = 2) {
color = asDiscrete("year")
fill = asDiscrete("year")
} +
facetGrid(y = "year")
coordFlip()
¶plotBase + geomViolin(quantiles = quantiles, quantileLines = true) + coordFlip()
geomViolin()
and geomBoxplot()
¶plotBase2 +
geomViolin(quantiles = quantiles, quantileLines = true, alpha = 0.5, size = 1, trim = false) +
geomBoxplot(width=.2, position = positionDodge(.2),
outlierShape = 21, outlierFill = "white", outlierSize = 2) {
color = asDiscrete("year")
fill = asDiscrete("year")
}