-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathBarGeomAndCountStat.kt
41 lines (35 loc) · 1.23 KB
/
BarGeomAndCountStat.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2021. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package frontendContextDemo.scripts
import frontendContextDemo.ScriptInBrowserContext
import org.jetbrains.letsPlot.geom.geomBar
import org.jetbrains.letsPlot.ggplot
import org.jetbrains.letsPlot.stat.statCount
object BarGeomAndCountStat {
@JvmStatic
@Suppress("DuplicatedCode")
fun main(args: Array<String>) {
ScriptInBrowserContext.eval("'geom_bar()' == 'stat_count'") {
val data = mapOf<String, Any>(
"cat1" to listOf("a", "a", "b", "a", "a", "a", "a", "b", "b", "b", "b"),
"cat2" to listOf("c", "c", "d", "d", "d", "c", "c", "d", "c", "c", "d")
)
val p = ggplot(data)
// bar (with count stat by default)
val barLayer = geomBar {
x = "cat1"
fill = "cat2"
}
// count stat (with bar geom by default)
val countLayer = statCount {
x = "cat1"
fill = "cat2"
}
// show two identical plots
(p + barLayer).show()
(p + countLayer).show()
}
}
}