3

I'm using the plotting function sizetree from library(plotrix) (Version: 3.8-1). This function has a showcount argument that allows some counts in parenthesis to show on the plot (see pic below).

But I wonder why when I use showcount=FALSE, the counts and parentheses around them don't go away? Is there any way to make them disappear?

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

rnorouzian
  • 7,397
  • 5
  • 27
  • 72

1 Answers1

2

The function seems to to have a bug in it. The function call itself recursively to add each of the columns, but the function neglects to pass along the showcount value to each of the subsequent calls. Here's one way to "patch" the function. Essentally we are making a copy and changing a line of code. This method is really fragile and may easily break with other versions of the package, but this was tested with 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

Then we can run

sizetree(h,showcount = FALSE)

to get sizetree without counts

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • I think [this question](https://stackoverflow.com/q/70726042/16762740) is exactly in line with your above answer. May I kindly ask if you could consider taking a look? – Simon Harmel Jan 15 '22 at 22:51