0

我想绘制一个直方图,表示 y 轴上的值 TP 和 x 轴上的方法。特别是我想根据“数据”列的值获得不同的数字。

在这种情况下,我想要一个值为 2,1,6,9,8,1,0 的第一个直方图和一个值为 10,10,16 的第二个直方图,...

ggplot 的 python 版本似乎与 R 版本略有不同。

            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

作为第一步,我试图只绘制一个直方图,但我收到了一个错误。

 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]: 

我尝试了不同的命令组合,但没有解决。

一旦解决了第一个问题,我希望根据“数据”的值对直方图进行分组。这可能可以通过'facet_wrap'

4

1 回答 1

0

这可能是因为您在ggplot()没有参数的情况下调用(不确定这是否可能。如果您认为是这样,请在http://github.com/yhat/ggplot上添加一个问题)。

无论如何,这应该工作:

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

不幸的是,使用 geom_bar 进行刻面还不能正常工作(仅当所有刻面都具有所有级别/ x 值时!)-> Bugreport

于 2014-07-10T16:57:55.180 回答