Use the labels
parameter to create an annotated Barchart.
%useLatestDescriptors
%use lets-plot
%use dataframe
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.5.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.1.0.
val mpg = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg.head(3)
DataFrame: rowsCount = 3, columnsCount = 12
val mpgData = mpg.toMap()
gggrid(
listOf(
letsPlot(mpgData) + geomBar(labels = layerLabels().line("@..count..")) { x = "trans" },
letsPlot(mpgData) + geomBar(
stat = Stat.sum(), size = 0,
labels = layerLabels().line("@..proppct..")
) { x = "trans"; y = "..n.." } + coordFlip()
),
widths = listOf(1, 1.2)
)
ggplot(mpgData) { x = "class"; fill = "drv" } +
geomBar(labels = layerLabels().line("@..proppct..").format("..proppct..", "{d} %")) +
ggsize(700, 400)
ggplot(mpgData) { x = "class"; fill = "drv" } +
geomBar(labels = layerLabels().line("@..proppct..").format("..proppct..", "{d} %"),
position = positionFill()) +
coordFlip() +
ggsize(700, 400)
Too thin for labels to fit in.
ggplot(mpgData) { x = "class"; fill = "drv" } +
geomBar(labels = layerLabels().line("@..proppct..").format("..proppct..", "{d} %"),
position = positionDodge()) +
ggsize(700, 400)