New parameters in theme() to customize the legend spacing and margins:
legend_box - arrangement of multiple legends ("horizontal" or "vertical");legend_box_just - justification of each legend within the overall bounding box ("top", "bottom", "left", "right", "center");legend_box_spacing - spacing between plotting area and legend box;
legend_margin - margin around each legend;
legend_spacing - spacing between legends, legend_spacing_x/legend_spacing_y - in the horizontal/vertical direction.from 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('displ', 'cty', )) + \
geom_point(aes(fill='drv', size='hwy'), shape=21) + \
scale_size(range=[1, 10], breaks=[15, 30, 40]) + \
theme(legend_position='bottom', legend_background=element_rect(size=1))
p
legend_margin¶p + theme(legend_margin=[10, 20])
legend_box¶p + theme(legend_box='horizontal')
legend_box_just¶p + theme(legend_box_just='center')
legend_box_spacing¶p + theme(legend_box='horizontal', legend_box_spacing=50)
legend_spacing¶p + theme(legend_box='horizontal', legend_spacing_x=50)