%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 mpgDf = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
mpgDf.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 mpgData = mpgDf.toMap()
quantileLines
¶val p = letsPlot(mpgData) { x = "hwy"; fill = "drv" }
gggrid(
plots = listOf(
p + geomDensity(color = "black", alpha = 0.75) +
ggtitle("geomDensity(): quantileLines=false (default)"),
p + geomDensity(color = "black", alpha = 0.75, quantileLines = true) +
ggtitle("geomDensity(): quantileLines=true")
),
ncol = 1,
) + ggsize(700, 600)
val p = letsPlot(mpgData) { x = "hwy"; y = "drv"; fill="drv" }
gggrid(
plots = listOf(
p + geomAreaRidges() +
ggtitle("geomAreaRidges(): quantileLines=false (default)"),
p + geomAreaRidges(quantileLines = true) +
ggtitle("geomAreaRidges(): quantileLines=true")
),
ncol = 2,
) + ggsize(900, 350)
val p = letsPlot(mpgData) { x = "drv"; y = "hwy"; fill="drv" }
gggrid(
plots = listOf(
p + geomViolin() + ggtitle("geomViolin(): quantileLines=false (default)"),
p + geomViolin(quantileLines = true) + ggtitle("geomViolin(): quantileLines=true")
),
ncol = 2,
) + ggsize(900, 350)
quantiles
¶val quantiles: List<Number> = listOf(0, 0.02, 0.3, 0.7, 0.98, 1)
val p = letsPlot(mpgData) { x = "hwy"; fill="drv" }
gggrid(
listOf(
p + geomDensity(color = "black", alpha = 0.75, quantileLines = true) +
ggtitle("geomDensity(): quantiles=[0.25, 0.5, 0.75] (default)"),
p + geomDensity(color = "black", alpha = 0.75, quantileLines = true, quantiles = quantiles) +
ggtitle("geomDensity(): quantiles=$quantiles")
),
ncol = 1,
) + ggsize(700, 600)
val p = letsPlot(mpgData) { x = "hwy"; y = "drv"; fill="drv" }
gggrid(
plots = listOf(
p + geomAreaRidges(quantileLines = true) +
ggtitle("geomAreaRidges(): quantiles=[0.25, 0.5, 0.75] (default)"),
p + geomAreaRidges(quantileLines = true, quantiles=quantiles) +
ggtitle("geomAreaRidges(): quantiles=$quantiles")
),
ncol = 2,
) + ggsize(900, 350)
val p = letsPlot(mpgData) { x = "drv"; y = "hwy"; fill="drv" }
gggrid(
plots = listOf(
p + geomViolin(quantileLines = true) + ggtitle("geomViolin(): quantiles=[0.25, 0.5, 0.75] (default)"),
p + geomViolin(quantileLines = true, quantiles=quantiles) + ggtitle("geomViolin(): quantiles=$quantiles")
),
ncol = 2,
) + ggsize(900, 350)
..quantile..
in Aesthetics Mapping¶val p = letsPlot(mpgData) { x = "hwy"; group = "drv" }
val quantilesN = run {
val n = 15
val step = 1.0 / (n-1)
List(n) { it * step }
}
gggrid(
plots = listOf(
p + geomDensity(color = "black", alpha = 0.95) +
ggtitle("geomDensity(): fill=null in aes (default)"),
p + geomDensity(color = "black", alpha = 0.95, quantiles = quantilesN) {
fill = "..quantile.."
} +
scaleFillGradient2(low = "white", mid = "#3F8F77", high = "white", midpoint = 0.5) +
ggtitle("geomDensity(): fill='..quantile..' in aes")
),
ncol = 1,
) + ggsize(700, 600)
val p = letsPlot(mpgData) { x = "hwy"; y = "drv" }
gggrid(
plots = listOf(
p + geomAreaRidges() + ggtitle("geomAreaRidges(): fill=null in aes (default)"),
p + geomAreaRidges() { fill = "..quantile.." } + ggtitle("geomAreaRidges(): fill='..quantile..' in aes")
),
ncol = 2,
) + ggsize(900, 350)
val p = letsPlot(mpgData) { x = "drv"; y = "hwy" }
gggrid(
plots = listOf(
p + geomViolin() + ggtitle("geomViolin(): fill=null in aes (default)"),
p + geomViolin() { fill = "..quantile.." } + ggtitle("geomViolin(): fill='..quantile..' in aes")
),
ncol = 2,
) + ggsize(900, 350)