%useLatestDescriptors
%use lets-plot
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.7.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.2.
val data = mapOf(
"x" to listOf(1, 1, 2, 2, 2),
"y" to listOf(1, 3, 2, 1, -3),
"grp" to listOf("a", "b", "a", "b", "c")
)
val p = letsPlot(data) { x = "x"; y = "y"; group = "grp" } +
geomBar(stat = Stat.identity, color = "pen") { fill = "grp" } +
scaleFillBrewer(palette = "Pastel1") +
theme(axisLineX = elementBlank(), axisTicks = elementBlank()) +
geomHLine(yintercept = 0, color = "pen", size = 0.5)
val w = 600
val h = 400
GGBunch()
.addPlot(p + geomLabel(position = positionStack()) { label = "y" } + ggtitle("Default"), 0, 0)
.addPlot(p + geomLabel(position = positionStack(0.0)) { label = "y" } + ggtitle("vjust = 0.0"), w, 0)
.addPlot(p + geomLabel(position = positionStack(0.3)) { label = "y" } + ggtitle("vjust = 0.3"), 0, h)
.addPlot(p + geomLabel(position = positionStack(0.5)) { label = "y" } + ggtitle("vjust = 0.5"), w, h)
.addPlot(p + geomLabel(position = positionStack(0.7)) { label = "y" } + ggtitle("vjust = 0.7"), 0, 2*h)
.addPlot(p + geomLabel(position = positionStack(1.0)) { label = "y" } + ggtitle("vjust = 1.0"), w, 2*h)
.show()
// position = "fill"
letsPlot(data) { x = "x"; y = "y"; group = "grp" } +
geomBar(stat = Stat.identity, position = positionFill(), color = "pen") { fill = "grp" } +
scaleFillBrewer(palette = "Pastel1") +
geomText(position = positionFill(0.5)) { label = "y" } +
theme(axisLineX = elementBlank(), axisTicks = elementBlank()) +
geomHLine(yintercept = 0, color = "pen", size = 0.5)