I have a data frame (df) which has correlations calculated for different genes with respect to different ID combinations. I want to get separate histogram plot based on the gene name (separate plot for separate gene). Also after plotting I want to know which genes have more deviations in their correlation values (Like more deviated from the median in each plot).
Example:
df
Gene ID_1 ID_2 Correlation
TNF 1175077258 1175075956 0.626115
TNF 1175077261 1175075956 0.542499
TNF 1175077261 1175077258 0.50113
TNF 1175077263 1175075956 0.431587
TNF 1175077263 1175077258 0.734858
TNF 1175077263 1175077261 0.622206
CCL2 952399885 952399878 0.632703
CCL2 952399894 952399878 0.622244
CCL2 952399894 952399885 0.697313
CCL2 952399923 952399878 0.687826
CCL2 952399923 952399885 0.612089
CCL2 952399923 952399894 0.603834
IL10 1068768000 1068767927 0.118955
IL10 1068768147 1068767927 0.32038
IL10 1068768147 1068768000 0.430287
IL10 1068768409 1068767927 0.335264
IL10 1068768409 1068768000 0.406426
IL10 1068768409 1068768147 0.546452
I tried the below code which only works when combining all genes together.
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams["figure.figsize"] = (8,6)
g1 = sns.histplot(df.Correlation)
g1.set(
xlim=(-1,1),
title="correlation"
)
g1.axvline(0.0, c='black', linestyle="--")
g1.axvline(df.Correlation.median(), c='red', linestyle="--")
The result/plot I am expecting is this (I have created this example plot in excel)