问题
This is my code
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"))
How do I remove the borders around the labels (Mark_1, Mark_2 etc) ?
This is the image that I get while plotting
回答1:
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
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)
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))
}
})
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)
来源:https://stackoverflow.com/questions/21374097/remove-label-borders-in-r-spie-plot