Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Possibility to not use pandas dataframes? #78

Closed
Ninontwik opened this issue Jun 9, 2021 · 4 comments
Closed

Possibility to not use pandas dataframes? #78

Ninontwik opened this issue Jun 9, 2021 · 4 comments

Comments

@Ninontwik
Copy link

Ninontwik commented Jun 9, 2021

First of all, thank you for the very nice package.

I use lists as input for all my boxplots, and I don't and don't want to use pandas. This is fine in seaborn, but I cannot get this to work with this package. At least, I think this is the problem. If I use:

ax = sns.boxplot(data=dat) results = add_stat_annotation(ax, data=dat, test='t-test_ind', text_format='star')
, where dat is a list containing three lists of equal length, which then are the three 'boxes'. The seaborn boxplot works perfectly but with add stat annotation I get the following error:
in get_box_data cat = box_plotter.plot_hues is None and boxName or boxName[0] TypeError: 'int' object is not subscriptable

So my guess is this has to do with the absence of box names but I am not sure. Is there a proper way to use your package without using pandas?

@trevismd
Copy link

Thank you for reporting this. Here is how you can use statannot before it gets fixed here or in another fork.
The examples below are for 2 groups but it should be the same with 3 or more.

This indeed fails

ax = sns.boxplot(data=[[1, 2, 3], [2, 5, 7]])
statannot.add_stat_annotation(ax, data=[[1, 2, 3], [2, 5, 7]], test="t-test_ind")

as well as

ax = sns.boxplot(x=[0, 0, 0, 1, 1, 1], y=[1, 2, 3, 2, 5, 7])
statannot.add_stat_annotation(ax, x=[1, 1, 1, 2, 2, 2], y=[1, 2, 3, 2, 5, 7], test="t-test_ind",
                              box_pairs=[(0, 1)])

because it is equivalent.
However, this works:

ax = sns.boxplot(x=[1, 1, 1, 2, 2, 2], y=[1, 2, 3, 2, 5, 7])
statannot.add_stat_annotation(ax, x=[1, 1, 1, 2, 2, 2], y=[1, 2, 3, 2, 5, 7], test="t-test_ind",
                              box_pairs=[(1, 2)])

When using data without specifying x and y, seaborn uses the indices of your 3 lists as group_names, making the first group_name equal to the first index, so 0 which then fails to be recognized as a possible box_name in statannot in the expression you mention (designed to identify when hues are specified).

So, if you can, concatenate your lists to make y, and provide an x list that matches this third example (and don't forget to provide box_pairs to compare) such as:

# Considering defined strings labels label1, label2, label3
x = [label1] * len(list_1) + [label2] * len(list2)+ [label3] * len(list3)
y = list1 + list2 + list3

(Or use pandas)

Let us know how it goes!

@trevismd
Copy link

If you wish, you can also modify add_stat_annotations to replace said line with
get_box_data cat = boxName if box_plotter.plot_hues is None else boxName[0].

@trevismd
Copy link

Oh, I just found this was proposed already in #73 which covers your bug.

@webermarcolivier
Copy link
Owner

Already covered in trevismd/statannotations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants