kandy 0.6.0 Help

Legend and Axis

val mpgDf = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv") mpgDf.head()

untitled

manufacturer

model

displ

year

cyl

trans

drv

cty

hwy

fl

class

1

audi

a4

18

1999

4

auto\(l5\)

f

18

29

p

compact

2

audi

a4

18

1999

4

manual\(m5\)

f

21

29

p

compact

3

audi

a4

2

2008

4

manual\(m6\)

f

20

31

p

compact

4

audi

a4

2

2008

4

auto\(av\)

f

21

30

p

compact

5

audi

a4

28

1999

6

auto\(l5\)

f

16

26

p

compact

mpgDf.plot { points { x(displ) y(hwy) color(manufacturer) size = 5.0 } layout.size = 600 to 250 }
Plot with Default Legend
mpgDf.plot { points { x(displ) y(hwy) color(manufacturer) { legend.type = LegendType.DiscreteLegend(nCol = 2) } size = 5.0 } layout { title = "Two columns legend" size = 600 to 250 } }
Legend with Two Columns
mpgDf.plot { points { x(displ) y(hwy) color(manufacturer) { legend.type = LegendType.DiscreteLegend(nCol = 2, byRow = true) } size = 5.0 } layout { title = "Two columns legend filled by rows" size = 600 to 250 } }
Filling Legend by Rows
mpgDf.plot { points { x(displ) y(hwy) color(manufacturer) { legend.type = LegendType.DiscreteLegend(nRow = 5) } size = 5.0 } layout { title = "Five rows legend and below" size = 700 to 400 style { axis.title { blank = true } legend.position = LegendPosition.Bottom } } }
Bottom Legend
mpgDf.plot { x(displ) y(hwy) points { size = 5.0 color(cty) symbol(drv) } layout.size = 700 to 350 }
Continuous Legend
mpgDf.plot { x(displ) y(hwy) points { size = 5.0 color(cty) symbol(drv) } layout { size = 700 to 350 style { legend { justification(1.0, 1.0) position(1.0, 1.0) direction = LegendDirection.HORIZONTAL } } } }
Legend with Horizontal Direction
mpgDf.plot { x(displ) y(hwy) points { size = 5.0 color(cty) { scale = continuous(range = Color.named("dark_blue")..Color.named("light_blue")) legend { name = "City MPG" type = LegendType.ColorBar(barHeight = 10.0, barWidth = 300.0) } } symbol(drv) { legend { name = "Drive-train" breaksLabeled("f" to "front", "r" to "rear", "4" to "4X4") } } } layout { size = 700 to 350 style { yAxis.line { blank = true } legend { justification(1.0, 1.0) position(1.0, 1.0) direction = LegendDirection.HORIZONTAL } } xAxisLabel = "Engine displacement (L)" yAxisLabel = "Highway MPG" } }
Configured Legend
Last modified: 13 May 2024