New theme() parameters allow to set the style for horizontal and vertical facet labels separately:
strip_background_x and strip_background_y parameters set the background of horizontal and vertical facet labels respectively, specified with element_rect();
strip_text_x and strip_text_y - horizontal and vertical facet labels, specified with element_text().
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
data = pd.DataFrame.from_records([
("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"),
])
data.columns = ("animal_type", "animal", "weight", "diet")
p = ggplot(data, aes(x='animal', y='weight')) + \
geom_bar(stat='identity') + \
facet_grid(x='animal_type', y='diet', scales='free') + \
theme_bw()
p
Change the style for facet labels:
p + theme(strip_text_x=element_text(face='bold'),
strip_background_x=element_rect(fill='pink'),
strip_text_y=element_text(face='italic'),
strip_background_y=element_rect(fill='light_blue'))
Hide horizontal facet labels:
p + theme(strip_text_x=element_blank())