orientation
property¶Some geoms treat each axis differently and, thus, can thus have two orientations.
The orientation
parameter specifies the axis that the layer' stat and geom should run along (x-axis by default).
%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(3)
DataFrame: rowsCount = 3, 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 |
val base = letsPlot(mpg.toMap()) + ggsize(800, 300)
val manufacturerMapping = asDiscrete("manufacturer", orderBy = "..count..")
val hideXLabel = theme(axisTitleX = "blank")
val hideYLabel = theme(axisTitleY = "blank")
// orientation "x" (default) : "manufacturer" is mapped to the x-axis.
val orientationX = base + geomBar(color = "paper") {
x = manufacturerMapping
fill = "class"
}
orientationX + hideXLabel
// Same but flipped coordinate system.
orientationX + coordFlip() + hideXLabel
// Orientation "y".
// The "manufacturer" is mapped to the y-axis.
val baseY = base + hideYLabel
baseY + geomBar(color = "white", orientation="y") {
y = manufacturerMapping
fill = "class"
}
baseY + geomBoxplot(width = 0.7, orientation = "y") {
y = "manufacturer"
x = "cty"
}
geomViolin()
¶letsPlot(mpg.toMap()) + geomViolin(trim = false, orientation = "y") { y="drv"; x = "cty"; fill = "drv"} +
geomBoxplot(alpha = 0.5, width = 0.3, orientation = "y") {
y = "drv"
x = "cty"
}
@file:DependsOn("org.apache.commons:commons-math3:3.6.1")
import org.apache.commons.math3.distribution.MultivariateNormalDistribution
val cov0 : Array<DoubleArray> = arrayOf(doubleArrayOf(1.0, -.8),
doubleArrayOf(-.8, 1.0))
val cov1 : Array<DoubleArray> = arrayOf(doubleArrayOf(10.0, .1),
doubleArrayOf(.1, .1))
val n = 200
val means0 : DoubleArray = doubleArrayOf(-2.0, 0.0)
val means1 : DoubleArray = doubleArrayOf(0.0, 1.0)
val xy0 = MultivariateNormalDistribution(means0, cov0).sample(n)
val xy1 = MultivariateNormalDistribution(means1, cov1).sample(n)
val dat = mapOf(
"x" to (xy0.map { it[0] } + xy1.map { it[0] }).toList(),
"y" to (xy0.map { it[1] } + xy1.map { it[1] }).toList(),
"c" to List(n){"A"} + List(n){"B"},
)
val p = letsPlot(dat) {x = "x"; y = "y"; color = "c"} + ggsize(600,300) +
geomPoint()
p
geomDensity()
¶p + geomDensity(size = 2)
p + geomDensity(size = 2, orientation = "y")
geomHistogram()
¶p + geomHistogram(fill = "rgba(0,0,0,0)")
p + geomHistogram(fill = "rgba(0,0,0,0)", orientation = "y")
geomFreqpoly()
¶p + geomFreqpoly(size = 2)
p + geomFreqpoly(size = 2, orientation = "y")
geomSmooth()
¶p + geomSmooth(seed = 42)
p + geomSmooth(orientation = "y", seed = 42)
geomBoxplot()
¶p + geomBoxplot(x = -10, color = "pen") +
geomBoxplot(y = -3, color = "pen", orientation = "y")
geomViolin()
¶p + geomViolin(x = -10, color = "pen", alpha = 0) +
geomViolin(y = -3, color = "pen", alpha = 0, orientation = "y")
p + geomViolin(mapping = {fill = "c"}, y = -2, color = "pen",
alpha = 0.3, position = positionIdentity, width = 3, showLegend = false,
orientation="y", trim = false)