Facet Strip Text Angle¶
Facet strip labels can be rotated with the angle parameter in elementText(). Use stripTextX for horizontal facet labels and stripTextY for vertical facet labels. Use stripText to change both.
In [1]:
%use lets-plot
In [2]:
LetsPlot.getInfo()
Out[2]:
In [3]:
val mtcars = mapOf(
"mpg" to listOf(21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8, 16.4),
"wt" to listOf(2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3.440, 3.440, 4.070),
"cyl" to listOf("6", "6", "4", "6", "8", "6", "8", "4", "4", "6", "6", "8")
)
Horizontal Y-Axis Strip Labels¶
By default, y-axis strip labels are vertical. When the labels are short, it may be more convenient to display them horizontally.
In [4]:
val basePlot = letsPlot(mtcars) { x = "mpg"; y = "wt" } +
geomPoint(color = "steelblue") +
facetGrid(y = "cyl") +
themeBW() +
theme(
panelBorder = elementRect(color = "gray20"),
stripBackgroundY = elementRect(fill = "aliceblue", color = "steelblue")
) +
ggtitle("Default strip label appearance") +
ggsize(height = 300, width = 500)
basePlot
Out[4]:
In [5]:
basePlot +
theme(
stripTextY = elementText(
angle = 0,
size = 24,
face = "bold",
color = "darkblue / 0.4"
)
) +
ggtitle("Natural strip text direction")
Out[5]:
Rotating Horizontal and Vertical Strip Labels¶
In [6]:
val sales = mapOf(
"region" to listOf("North", "North", "South", "South", "North", "North", "South", "South"),
"segment" to listOf("Retail", "Retail", "Retail", "Retail", "Online", "Online", "Online", "Online"),
"quarter" to listOf("Q1", "Q2", "Q1", "Q2", "Q1", "Q2", "Q1", "Q2"),
"value" to listOf(12, 15, 9, 11, 16, 18, 13, 17)
)
letsPlot(sales) { x = "quarter"; y = "value" } +
geomBar(stat = Stat.identity, fill = "steelblue", color = "white") +
facetGrid(x = "region", y = "segment") +
themeBW() +
theme(
stripTextX = elementText(angle = 35, size = 13, face = "bold", color = "steelblue"),
stripTextY = elementText(angle = 35, size = 13, face = "bold", color = "salmon"),
stripBackgroundX = elementRect(fill = "aliceblue", color = "cadetblue"),
stripBackgroundY = elementRect(fill = "lemonchiffon", color = "tan")
) +
ggsize(700, 420) +
ggtitle("Custom angles for facet strip labels")
Out[6]: