0

I would like to plot an histogram representing the value TP on the y axis and the method on the x axis. In particular I would like to obtain different figures according to the value of the column 'data'.

In this case I want a first histogram with values 2,1,6,9,8,1,0 and a second histogram with values 10,10,16,...

The python version of ggplot seems to be slightly different by the R ones.

            FN FP  TN  TP                   data  method
method                                              
SS0208  18  0  80   2  A p=100 n=100 SNR=0.5  SS0208
SS0408  19  0  80   1  A p=100 n=100 SNR=0.5  SS0408
SS0206  14  9  71   6  A p=100 n=100 SNR=0.5  SS0206
SS0406  11  6  74   9  A p=100 n=100 SNR=0.5  SS0406
SS0506  12  6  74   8  A p=100 n=100 SNR=0.5  SS0506
SS0508  19  0  80   1  A p=100 n=100 SNR=0.5  SS0508
LKSC    20  0  80   0  A p=100 n=100 SNR=0.5    LKSC
SS0208  10  1  79  10   A p=100 n=100 SNR=10  SS0208
SS0408  10  0  80  10   A p=100 n=100 SNR=10  SS0408
SS0206   4  5  75  16   A p=100 n=100 SNR=10  SS0206

As a first step I have tried to plot only one histogram and I received an error.

 df = df[df.data == df.data.unique()[0]]

In [65]: ggplot() + geom_bar(df, aes(x='method', y='TP'), stat='identity')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-65-dd47b8d85375> in <module>()
----> 1 ggplot() + geom_bar(df, aes(x='method', y='TP'), stat='identity')

TypeError: __init__() missing 2 required positional arguments: 'aesthetics' and 'data'w

In [66]: 

I have tried different combinations of commands but I did not solve.

Once that this first problem has been solved I would like the histograms grouped according to the value of 'data'. This could probably be done by 'facet_wrap'

1

1 Answer 1

0

This is probably because you called ggplot() without an argument (Not sure if that should be possible. If you think so, please add a issue on http://github.com/yhat/ggplot).

Anyway, this should work:

ggplot(df, aes(x='method', y='TP')) + geom_bar(stat='identity')

Unfortunately, faceting with geom_bar doesn't work yet properly (only when all facets have all levels/ x values!) -> Bugreport

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.