How to add additional plots to a seaborn FacetGrid and specify colors

I think you want units in the call to relplot and then add a layer of lineplot using map: import seaborn as sns import pandas as pd fm = sns.load_dataset(‘fmri’).query(“event == ‘stim'”) g = sns.relplot( data=fm, kind=’line’, col=”region”, x=’timepoint’, y=’signal’, units=”subject”, estimator=None, color=”.7″ ) g.data = fm # Hack needed to work around bug on … Read more

Facetgrid change xlabels

You can access the individual axes of the FacetGrid using the axes property, and then use set_xlabel() on each of them. For example: import seaborn as sns import matplotlib.pyplot as plt sns.set(style=”ticks”, color_codes=True) tips = sns.load_dataset(“tips”) g = sns.FacetGrid(tips, col=”time”, hue=”smoker”) g = g.map(plt.scatter, “total_bill”, “tip”, edgecolor=”w”) g.axes[0,0].set_xlabel(‘axes label 1’) g.axes[0,1].set_xlabel(‘axes label 2’) plt.show() Note … Read more

How to add a title to Seaborn Facet Plot

Updating slightly, with seaborn 0.11.1: Seaborn’s relplot function creates a FacetGrid and gives each subplot its own explanatory title. You can add a title over the whole thing: import seaborn as sns tips = sns.load_dataset(‘tips’) rp = sns.relplot(data=tips, x=’total_bill’, y=’tip’, col=”sex”, row=’smoker’, kind=’scatter’) # rp is a FacetGrid; # relplot is a nice organized way … Read more

How to order data by value within ggplot facets

We can use (1) reorder_within() function to reorder term within tissue facets. library(tidyverse) library(forcats) tdat <- tdat %>% mutate(term = factor(term), tissue = factor(tissue, levels = c(“tissue-C”, “tissue-A”, “tissue-D”, “tissue-B”), ordered = TRUE)) reorder_within <- function(x, by, within, fun = mean, sep = “___”, …) { new_x <- paste(x, within, sep = sep) stats::reorder(new_x, by, … Read more