theme()
¶New parameters in theme()
to customize the legend key:
legendKey
- background underneath legend keys, set with elementRect()
legendKeySize
- size of legend keyslegendKeyWidth
- key background widthlegendKeyHeight
- key background heightlegendKeySpacing
- spacing between legend keyslegendKeySpacingX
- spacing in the horizontal directionlegendKeySpacingY
- spacing in the vertical direction%useLatestDescriptors
%use lets-plot
%use dataframe
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.9.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.5.1.
import javax.imageio.ImageIO
import java.net.URL
val url = URL("https://github.com/JetBrains/lets-plot/raw/master/docs/f-24g/images/theme_legend_scheme.png")
ImageIO.read(url)
val mpg = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg.head(3)
DataFrame: rowsCount = 3, columnsCount = 12
untitled | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.800000 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.800000 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.000000 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
val p = letsPlot(mpg.toMap()) { x = "hwy" } +
geomDotplot(color="pen") { fill = "class" } +
theme(legendBackground = elementRect(size = 0.5))
p
Add background underneath legend keys:
val p1 = p + theme(legendKey = elementRect(fill = "#efedf5", color = "#756bb1"))
p1
Change size of legend keys:
p1 + theme(legendKeySize = 30)
val p2 = p1 + theme(legendKeyWidth = 80, legendKeyHeight = 20)
p2
Add spacing between legend keys:
p2 + theme(legendKeySpacingY = 10)