How can I configure box.color in directlabels “draw.rects”?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 05:05:59

This seems to be a hack but it worked. I just redefined the draw.rects function, since I could not see how to pass arguments to it due to the clunky way that directlabels calls its functions. (Very like ggplot-functions. I never got used to having functions be character values.):

assignInNamespace( 'draw.rects',  
function (d, ...) 
{
    if (is.null(d$box.color)) 
        d$box.color <- "red"
    if (is.null(d$fill)) 
        d$fill <- "white"
    for (i in 1:nrow(d)) {
        with(d[i, ], {
            grid.rect(gp = gpar(col = box.color, fill = fill), 
                vp = viewport(x, y, w, h, "cm", c(hjust, vjust), 
                  angle = rot))
        })
    }
    d
}, ns='directlabels')
dlp <- direct.label(p, "angled.boxes")
dlp

I also have a response from the package author, Toby Hocking. Either of these will work:

my.dl <- list(dl.trans(box.color="red"),"draw.rects")
direct.label(p, list("far.from.others.borders","calc.boxes", "enlarge.box", "my.dl"))

OR (shortcut)

my.dl <- list(box.color="red", "draw.rects")
direct.label(p, list("far.from.others.borders","calc.boxes", "enlarge.box", "my.dl"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!