New theme()
parameters allow to set the style for horizontal and vertical facet labels separately:
stripBackgroundX
and stripBackgroundY
parameters set the background of horizontal and vertical facet labels respectively, specified with elementRect()
;
stripTextX
and stripTextY
- horizontal and vertical facet labels, specified with elementText()
.
%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.
val df = dataFrameOf("animal_type", "animal", "weight", "diet")(
"pet", "cat", 5, "carnivore",
"pet", "dog", 10, "carnivore",
"pet", "rabbit", 2, "herbivore",
"pet", "hamster", 1, "herbivore",
"farm", "cow", 500, "herbivore",
"farm", "pig", 100, "carnivore",
"farm", "horse", 700, "herbivore",
)
val p = letsPlot(df.toMap()) { x = "animal"; y = "weight" } +
geomBar(stat = Stat.identity) +
facetGrid(x = "animal_type", y = "diet", scales = "free") +
themeBW()
p
Change the style for facet labels:
p + theme(stripTextX = elementText(face = "bold"),
stripBackgroundX = elementRect(fill = "pink"),
stripTextY = elementText(face = "italic"),
stripBackgroundY = elementRect(fill = "light_blue"))
Hide horizontal facet labels:
p + theme(stripTextX = elementBlank())