Grouped Bars
val dataset = dataFrameOf(
"day" to listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
"coffee" to listOf(0.81, 0.78, 0.72, 0.65, 0.73, 0.49, 0.38),
"tea" to listOf(0.12, 0.16, 0.21, 0.26, 0.24, 0.22, 0.30),
"soda" to listOf(0.07, 0.06, 0.07, 0.09, 0.03, 0.29, 0.32),
).gather("coffee", "tea", "soda").into("drink", "amount")
dataset.groupBy("drink").plot {
layout.title = "Weekly Beverage Consumption Trends"
bars {
x("day")
y("amount")
fillColor("drink") {
scale = categorical(
"coffee" to Color.hex("#6F4E37"),
"tea" to Color.hex("#C2D4AB"),
"soda" to Color.hex("#B5651D")
)
}
}
}
val days = listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
val coffee = listOf(0.81, 0.78, 0.72, 0.65, 0.73, 0.49, 0.38)
val tea = listOf(0.12, 0.16, 0.21, 0.26, 0.24, 0.22, 0.30)
val soda = listOf(0.07, 0.06, 0.07, 0.09, 0.03, 0.29, 0.32)
val dataset = mapOf(
"day" to days + days + days,
"amount" to coffee + tea + soda,
"drink" to List(7) { "coffee" } + List(7) { "tea" } + List(7) { "soda" }
)
dataset.plot {
layout.title = "Weekly Beverage Consumption Trends"
groupBy("drink") {
bars {
x("day")
y("amount")
fillColor("drink") {
scale = categorical(
"coffee" to Color.hex("#6F4E37"),
"tea" to Color.hex("#C2D4AB"),
"soda" to Color.hex("#B5651D")
)
}
}
}
}
Last modified: 06 December 2023