#!/usr/bin/env python # coding: utf-8 # # Residual plot # In[1]: import pandas as pd from lets_plot import * from lets_plot.bistro.residual import * LetsPlot.setup_html() # In[2]: df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv") print(df.shape) df.head() # ## Default plot # In[3]: residual_plot(df, "petal_length", "petal_width") # ## Scatter plot (`method='none'`) # In[4]: residual_plot(df, "petal_length", "petal_width", method='none', hline=False, marginal='none') + theme_classic() # ## Change geom type # In[5]: residual_plot(df, "petal_length", "petal_width", geom='tile', marginal="hist:tr") + \ ggsize(600, 200) # ## Change method # In[6]: residual_plot(df, "petal_length", "petal_width", method='loess', span=.25, max_n=25) # ## Geometries customization # In[7]: residual_plot(df, "petal_length", "petal_width", size=5, color="#feb24c", alpha=1/3) # In[8]: residual_plot(df, "petal_length", "petal_width", geom='none', color="black", hline=False) + \ geom_hline(yintercept=0, color="black") + \ geom_point(size=5, shape=21, color="black", fill="#feb24c") # In[9]: residual_plot(df, "petal_length", "petal_width", hline=False, marginal='none') + \ geom_smooth(method='loess', se=True, level=.99, seed=42) # ## Marginal layers customization # In[10]: residual_plot(df, "petal_length", "petal_width", marginal="box:lb:.03,hist:t:.4,hist:r", color="black") + \ ggmarginal("tr", layer=geom_area(stat='density', color="magenta", fill="magenta", alpha=.1)) + \ theme_minimal() # ## Grouping # In[11]: residual_plot(df, "petal_length", "petal_width", color_by="species") # ## Interaction with other layers # In[12]: residual_plot(df, "petal_length", "petal_width", geom='tile', binwidth=[.4, .1], marginal='none') + \ coord_fixed(ratio=.25, flip=True) + \ theme(axis_ticks="blank", axis_text="blank", axis_line="blank") # In[13]: residual_plot(df, "petal_length", "petal_width", color="white", binwidth=.1, marginal="hist:r") + \ ylab("residual") + \ theme_bw() + theme(text=element_text(family="monospace")) + \ flavor_high_contrast_dark()