如何解决试图找到一种使用mutate在ggplot2条形图中对行进行排序的方法
我有以下csv数据:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function array>) with argument(s) of type(s): (list(list(array(int64,1d,C))))
* parameterized
In definition 0:
TypingError: array(int64,C) not allowed in a homogeneous sequence
raised from /home/bellinger/anaconda3/lib/python3.7/site-packages/numba/typing/npydecl.py:460
In definition 1:
TypingError: array(int64,C) not allowed in a homogeneous sequence
raised from /home/bellinger/anaconda3/lib/python3.7/site-packages/numba/typing/npydecl.py:460
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<built-in function array>)
[2] During: typing of call at <ipython-input-108-17a4ebeac76c> (4)
File "<ipython-input-108-17a4ebeac76c>",line 4:
def test(x):
<source elided>
return np.array([[x,x],[x,x]])
我正在使用以下R代码创建图表:
component,command,error,errPercentage
init,acceptZone,MAX_ZONES,63.78014743
init,ERR_ZONE,32.93971707
init,acceptRefer,MAX_REFER,29.41176471
init,createZone,2.47576316
init,getZone,NO_ZONE,1.107557237
init,joinZone,28.9197955
init,ZONE_FULL,1.783299434
init,tempSet,RW_ONLY,17.30486009
init,removeSet,NON_AVAIL,1.50930378
init,sendSet,SEND_DEFERRED,2.529487652
init,SEND_CANCELED,1.036675267
init,updateSet,2.603311007
这是产生的图表:
我想要按errPercentage排序的行,因此acceptRefer和joinZone应该在另一个下面。我可以用barplot()做到这一点,但是ggplot却大不相同(但是我喜欢外观的改进,所以我想坚持下去)。
解决方法
您的数据集中每个command
值都有多个值。当您绘制条形图时,这些值将加在一起以获得总和。例如
“ acceptZone”具有值“ MAX_ZONES”和“ ERR_ZONE”,它们的总和为63.8 + 32.9 = 96.7。但是默认情况下,fct_reorder
函数不取值的总和,而是取组中所有值的中位数。您需要更改摘要功能以使用总和
这可以做到:
df %>%
mutate(command = fct_reorder(command,errPercentage,.fun=sum,.desc = FALSE)) %>%
ggplot(aes(x=errPercentage,y=command)) +
geom_col(fill="#f68060",alpha=.6,width=.4) +
xlab("Error %") +
labs(title="RPC Error Rates") +
theme_bw()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。