3

Here is a Minimal, Complete and Verifiable toy dataset for my problem:

genes = pd.Series(["Gene1"] * 16 + ["Gene2"] * 16)
conditions = pd.Series(np.tile(np.array(["Condition1"] * 8 + ["Condition2"] * 8), 2))
wellID = pd.Series(np.array(["W1"] * 4 + ["W2"] * 4 + ["W3"] * 4 + ["W4"] * 4 + ["W5"] * 4 + ["W6"] * 4 + ["W7"] * 4 + ["W8"] * 4))
fluo = pd.Series(np.array([np.sort(np.random.logistic(size=4)) for _ in range(8)]).flatten())
cycles = pd.Series(np.tile(np.array([0, 1, 2, 3]), 8))
df = pd.concat([genes, conditions, wellID, cycles, fluo], axis=1)
df.columns = ["Gene", "Condition", "WellID", "Cycle", "Fluo"]

It is composed of 2 genes for 2 conditions having each 2 replicates (1 replicate has 1 unique WellID for which there are 4 cycles, 1 measured fluo point per cycle).

I'm able to create the line plot I want isolating one gene with this command:

sns.lineplot(x="Cycle", y="Fluo", hue="Condition", units="WellID", estimator=None, data=df.loc[df.Gene == "Gene1"])

I had to use both units and estimator so that I can see the 2 replicates (and not an aggregated curve per Gene/Condition.

Finally, I wanted to use FacetGrid to see this plot for the 2 genes so I did:

g = sns.FacetGrid(df, col="Gene", hue="Condition", col_wrap=5)
g.map(sns.lineplot, "Cycle", "Fluo");

But then if I had the keywords "units" and "estimator", I have an error saying the "ValueError: Could not interpret input 'WellID'".

I could only display the plots with the 2 replicates aggregated.

mbahin
  • 129
  • 2
  • 10
  • [Please don't upload images of data or code on SO](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question) – Josh Friedlander Mar 11 '19 at 14:40
  • How should I show a head of DataFrame then? – mbahin Mar 11 '19 at 14:44
  • `df.head().to_dict()` – Chris Adams Mar 11 '19 at 14:45
  • Point is, you should not show *your* dataframe at all. But rather create a minimal dataset within the code to reproduce the issue. See [mcve] and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – ImportanceOfBeingErnest Mar 11 '19 at 14:46
  • 1
    Thanks, I just produced a Minimal, Complete and Verifiable toy dataset. I should be easier to help me! :) – mbahin Mar 12 '19 at 13:16

1 Answers1

9

Pass it as args to the lineplot function

g = sns.FacetGrid(df, col="Gene", hue="Condition", col_wrap=5)
g.map(sns.lineplot, "Cycle","Fluo", "WellID")
plt.show()

enter image description here

5norre
  • 748
  • 7
  • 9
  • 2
    This actually passes `"WellID"` to the `hue` parameter of `sns.lineplot` resulting in a very colorful plot if you have lots of lines. How to pass it explicitly as value for the `units` parameter? – Stanley F. Jul 19 '19 at 09:53