删除R Spie图中的标签边框 [英] Remove label borders in R Spie plot

查看:76
本文介绍了删除R Spie图中的标签边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

require(caroline)
   x <- c(100, 90, 80, 15, 120, 25)
   y <- c(120, 120, 60, 10, 120, 15)
   names(x) <- c("Mark_1", "Mark_2", "Mark_3", "Mark_4", "Mark_5", "Mark_6")
   spie.sales <- spie(x, y,col=rainbow(length(x)),bg=c("black", "violetred1", 
                                                       "cornsilk","red", "green", "white"))

如何删除标签(Mark_1,Mark_2等)周围的边框?

How do I remove the borders around the labels (Mark_1, Mark_2 etc) ?

这是我在绘制时得到的图像

This is the image that I get while plotting

推荐答案

尽管可以在加载caroline包之前使用函数fixInNamespace修改spie函数,但我更喜欢修改副本代替该功能.

Although it would be possible to use the function fixInNamespace to modify the spie function before loading the caroline package, I prefer to modify a copy of the function instead.

## Create copy of spie
spie2 <- spie

此外,您可以保留绘制矩形的选项.因此,在此处将新参数labRects添加到了新函数中.当该对象的值为FALSE时,将不会绘制矩形. TRUE时,将生成原始图.

Also, you can maintain the option of plotting the rectangles. So a new argument, labRects, is added here to the new function. When the value of this object is FALSE, no rectangles will be plotted. When TRUE, the original plot is produced.

## Add new argument to spie2 function
formals(spie2) <- c(formals(spie), labRects = FALSE)

然后找到功能body的哪些部分需要更改并进行更改

Then find what part of the function body needs changing and change it

## Assign new code into the appropriate part of the body of the function
body(spie2)[[9]][[4]][[8]][[3]][[2]] <- substitute({
    if(labRects) {
        grid.rect(x = cos(angleAnn) * maxx, y = sin(angleAnn) * maxx, 
            width = 1.5 * stringWidth(x$namesSlices[i]), height = 1.5 * 
            stringHeight(x$namesSlices[i]), default.units = "native", 
            gp = gpar(col = col[i], fill = "white", lwd = 2))
    }
})

由于Zbynek指出,spie函数和新的spie2函数都依赖于"caroline"包中未导出的.spie函数,因此我们需要将spie2的环境更改为与spie匹配,以允许访问.spie函数.

Because, as Zbynek notes, the spie function and the new spie2 function both rely on the non-exported .spie function from the "caroline" package, we need to change the environment of spie2 to match that of spie to allow access to the .spie function.

## Change environment of spie2 to "caroline"
environment(spie2) <- environment(spie)

## ...and plot
spie.sales <- spie2(x, y,col=rainbow(length(x)),
  bg=c("black", "violetred1", "cornsilk","red", "green", "white"),
  labRects = FALSE)

这篇关于删除R Spie图中的标签边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆