该函数似乎有一个错误。该函数递归地调用自身来添加每一列,但该函数忽略传递showcount
对每个后续调用的值。这是“修补”该函数的一种方法。本质上,我们正在制作副本并更改一行代码。这种方法确实很脆弱,可能很容易与其他版本的包一起破坏,但这是经过测试的plotrix_3.7-8
.
sizetree <- plotrix::sizetree
environment(sizetree) <- globalenv()
# This "path" navigates the AST for the function to find the offending line of code
path <- c(8, 3, 5, 4, 2, 3, 2, 3, 2, 3, 8, 3, 5)
orig <- body(sizetree)[[path]]
orig
## Problem line, no showcount= parameter
# sizetree(nextx, right, top, right + 1, lastcenter = top - xfreq[bar]/2,
# showval = showval, stacklabels = stacklabels, firstcall = FALSE,
# col = newcol, border = border, base.cex = base.cex)
## fix it up
scall <- orig
scall$showcount <- quote(showcount)
body(sizetree)[[path]] <- scall
然后我们就可以运行
sizetree(h,showcount = FALSE)
to get
![sizetree without counts](https://i.stack.imgur.com/zjODT.png)