theme()¶New parameters in theme() to customize the legend key:
legend_key - background underneath legend keys, set with element_rect()legend_key_size - size of legend keyslegend_key_width - key background widthlegend_key_height - key background heightlegend_key_spacing - spacing between legend keyslegend_key_spacing_x - spacing in the horizontal directionlegend_key_spacing_y - spacing in the vertical directionfrom IPython.display import Image
display(Image('images/theme_legend_scheme.png'))
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
mpg = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
mpg.head(3)
p = ggplot(mpg, aes(x='hwy')) + \
geom_dotplot(aes(fill='class'), color='pen') + \
theme(legend_background=element_rect(size=0.5))
p
Add background underneath legend keys:
p1 = p + theme(legend_key=element_rect(fill='#efedf5', color='#756bb1'))
p1
Change size of legend keys:
p1 + theme(legend_key_size=30)
p2 = p1 + theme(legend_key_width=80, legend_key_height=20)
p2
Add spacing between legend keys:
p2 + theme(legend_key_spacing_y=10)