删除图中的文本

问题描述

我正在使用来自 sizetree(版本:library(plotrix))的绘图函数 3.8-1。此函数一个 showcount 参数,允许括号中的一些计数显示在图上(见下图)。

但我想知道为什么当我使用 showcount=FALSE 时,它们周围的计数和括号不会消失?有什么办法可以让它们消失吗?

h = "
sssss ooooooo ggggg tttt
a     1       1     0
a     2       1     1
b     1       1     0
b     1       2     0
c     2       1     0
c     3       2     1
d     1       1     0
d     1       1     0
e     1       1     0"
h = read.table(text=h,h=T)

library(plotrix)
plotrix::sizetree(h,showcount = FALSE)

enter image description here

解决方法

该函数似乎存在错误。该函数以递归方式调用自身以添加每一列,但该函数忽略将 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,8,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)

得到 sizetree without counts