The 'newline' character (\n
) now works as a 'line break' in the facet titles.
Automatic line breaking is performed according to the text length limit specified with parameters labWidth
in facetWrap()
and xLabWidth
/yLabWidth
in facetGrid()
.
The margins around the facet titles are controlled by the margin
parameter in elementText()
.
Horizontal and vertical justifications - using hjust
and vjust
parameter in elementText()
.
%useLatestDescriptors
%use lets-plot
%use dataframe
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.7.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.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 animal", "cow", 500, "herbivore",
"farm animal", "pig", 100, "carnivore",
"farm animal", "horse", 700, "herbivore",
)
val p = letsPlot(df.toMap()) { x = "animal"; y = "weight" } +
geomBar(stat = Stat.identity) +
themeBW() +
theme(panelGridMinor = elementBlank())
p + facetWrap(facets = "animal_type", ncol = 2, scales = "free")
labWidth
-parameters¶p + facetWrap(facets = "animal_type", ncol = 2, scales = "free", labWidth = 6)
p + facetGrid(x = "animal_type", y = "diet", scales = "free", xLabWidth = 6)
\n
in Facet Values¶val df2 = df.update { animal_type }.with { it.replace(' ', '\n') }
val p2 = letsPlot(df2.toMap()) { x = "animal"; y = "weight" } +
geomBar(stat = Stat.identity) +
themeBW() +
theme(panelGridMinor = elementBlank())
p2 + facetGrid(x = "animal_type", y = "diet", scales = "free")
p2 + facetWrap(facets = listOf("animal_type", "diet"), ncol = 4, scales = "free")
p2 + facetWrap(facets = listOf("animal_type", "diet"), ncol = 4, scales = "free") +
theme(stripText = elementText(hjust = 1, vjust = 1))
p2 + facetGrid(x = "animal_type", y = "diet", scales = "free") +
theme(stripText = elementText(margin = listOf(10, 30), hjust = 0, vjust = 1))