geomLineRange()
geomPointRange()
geomErrorBar()
geomCrossbar()
geomRibbon()
You can flip opientation of these geometries simply by flipping their positional aesthetics mapping.
Note: when flipping aesthetics, in certain cases, you will have to also change the position adjustment of the geometry.
For example, when flipping orientation from vertical to horizontal, positionDodge()
should be replaced with positionDodgeV()
(i.e. "vertical dodge").
%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 df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/ToothGrowth.csv")
val errDf = df.groupBy { supp and dose }.aggregate {
mean { len } into "length"
min { len } into "len_min"
max { len } into "len_max"
}.sortBy { supp }
errDf
DataFrame: rowsCount = 6, columnsCount = 5
supp | dose | length | len_min | len_max |
---|---|---|---|---|
OJ | 0.500000 | 13.230000 | 8.200000 | 21.500000 |
OJ | 1.000000 | 22.700000 | 14.500000 | 27.300000 |
OJ | 2.000000 | 26.060000 | 22.400000 | 30.900000 |
VC | 0.500000 | 7.980000 | 4.200000 | 11.500000 |
VC | 1.000000 | 16.770000 | 13.600000 | 22.500000 |
VC | 2.000000 | 26.140000 | 18.500000 | 33.900000 |
val errorbarV = geomErrorBar(position = positionDodge(0.95)) { x = "dose"; ymin = "len_min"; ymax = "len_max" }
val errorbarH = geomErrorBar(position = positionDodgeV(0.95)) { y = "dose"; xmin = "len_min"; xmax = "len_max" }
gggrid(
listOf(
letsPlot(errDf.toMap()) { color = "supp" } + errorbarV + ggtitle("Vertical"),
letsPlot(errDf.toMap()) { color = "supp" } + errorbarH + ggtitle("Horizontal")
)
)
val p = letsPlot(errDf.toMap()) { y = "dose"; x = "length"; xmin = "len_min"; xmax = "len_max"; color = "supp" } +
xlab("Tooth length [mm]")
gggrid(
listOf(
p + geomCrossbar(position = positionDodgeV(0.95)) + ggtitle("geomCrossbar()"),
p + geomPointRange(position = positionDodgeV(0.95)) + ggtitle("geomPointRange()"),
p + geomLineRange(position = positionDodgeV(0.95)) + ggtitle("geomLineRange()"),
p + geomRibbon() + ggtitle("geomRibbon()")
),
ncol = 2, vspace = 20.0
)