如何在directlabels"draw.rects"中配置box.color?

a d*_*ben 4 r ggplot2 direct-labels

这是我的工作示例:

library(ggplot2)
library(directlabels)  # ver 2014.6.13 via r-forge
DF <- expand.grid(z = seq(1, 3001, by=10), k = seq(from=0.5, to=5, by=0.25))

# Defines the function value for each z-k combination
DF$dT <- with(DF, -0.07 * z * (1/2.75 - 1/k))

p <- ggplot(DF, aes(x = z, y = k, z = dT)) +  theme_bw() + 
 stat_contour(aes(colour=..level..), breaks=c(seq(from=-40, to=0, by=5), c(seq(from=5, to=150, by=10))))
angled.boxes <- list("far.from.others.borders","calc.boxes","enlarge.box","draw.rects")
direct.label(p, "angled.boxes")
Run Code Online (Sandbox Code Playgroud)

看起来像这样: 在此输入图像描述

我想将标签的框边框颜色变为"白色",但我看不出怎么做.在包的新闻中,写道:

2.5 --- 2012年4月6日

draw.rects具有可配置的颜色,默认为黑色.

并且看作"angled.boxes"的列表包括:

angled.boxes <- list("far.from.others.borders","calc.boxes","enlarge.box","draw.rects")
Run Code Online (Sandbox Code Playgroud)

我想这是可能的,但是怎么样?

42-*_*42- 7

这似乎是一个黑客,但它的工作原理.我刚刚重新定义了这个draw.rects函数,因为我看不到如何将参数传递给它,因为直接标记调用它的函数很笨拙.(非常像ggplot-functions.我从来不习惯将函数作为字符值.):

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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述