我想用radial.pie()
制作一个饼图。但是在图表的左侧有0
,我想删除它。
代码:
pie2 <- list(0:3, 1:6, 2:5, 1:4, 0:7, 4:8, 2:9, 0:1, 0:4)
radial.pie(pie2, labels = letters[2:10])
此代码为我们提供了这个图表:
因此,您会在图表左侧看到0
,标签“f”旁边。有任何想法吗
删除它?
答案 0 :(得分:2)
看起来xlab
和ylab
参数永远不会在radial.pie
函数中传递。下面是函数(radial.pie.alt
)的修改版本,其中这些参数成功传递:
radial.pie.alt <- function(radial.extents, sector.edges = NULL, sector.colors = NULL,
cs1 = c(0, 1), cs2 = c(0, 1), cs3 = c(0, 1), alpha = 1, labels = NA,
label.pos = NULL, radlab = FALSE, start = 0, clockwise = FALSE,
label.prop = 1.1, radial.lim = NULL, main = "", xlab = "",
ylab = "", mar = c(2, 2, 3, 2), show.grid = TRUE, show.grid.labels = 4,
show.radial.grid = TRUE, grid.col = "gray", grid.bg = "transparent",
grid.unit = NULL, radial.labels = NULL, boxed.radial = TRUE,
add = FALSE, ...)
{
if (is.null(radial.lim))
radial.lim <- range(radial.extents)
if (is.null(sector.edges)) {
if (clockwise)
sector.edges <- seq(2 * pi + start, start, length.out = length(radial.extents) +
1)
else sector.edges <- seq(start, 2 * pi + start, length.out = length(radial.extents) +
1)
}
if (is.null(label.pos))
label.pos <- sector.edges[-length(sector.edges)] + diff(sector.edges)/2
if (show.grid) {
if (length(radial.lim) < 3)
grid.pos <- pretty(radial.lim)
else grid.pos <- radial.lim
if (grid.pos[1] < radial.lim[1])
grid.pos <- grid.pos[-1]
maxlength <- max(grid.pos - radial.lim[1])
} else {
grid.pos <- NA
maxlength <- diff(radial.lim)
}
oldpar <- par("xpd", "mar", "pty")
if (!add) {
par(mar = mar, pty = "s")
maxrad <- max(unlist(radial.extents))
plot(0, xlim = c(-maxrad, maxrad), ylim = c(-maxrad,
maxrad), type = "n", axes = FALSE, xlab=xlab, ylab=ylab)
if (show.grid)
radial.grid(labels = labels, label.pos = label.pos,
radlab = radlab, radial.lim = radial.lim, start = start,
clockwise = clockwise, label.prop = label.prop,
grid.pos = grid.pos, grid.col = grid.col, grid.bg = grid.bg)
}
fadeColor <- function(col, nfades) {
rgbcol <- col2rgb(col)
redinc <- (255 - rgbcol[1])/nfades
reds <- (rgbcol[1] + 0:nfades * redinc)/255
greeninc <- (255 - rgbcol[2])/nfades
greens <- (rgbcol[2] + 0:nfades * greeninc)/255
blueinc <- (255 - rgbcol[3])/nfades
blues <- (rgbcol[3] + 0:nfades * blueinc)/255
return(rgb(reds[1:nfades], greens[1:nfades], blues[1:nfades]))
}
nsectors <- length(radial.extents)
if (is.list(radial.extents)) {
if (is.null(sector.colors))
sector.colors <- rainbow(nsectors)
for (sector in 1:nsectors) {
annuli <- radial.extents[[sector]]
annulus.colors <- fadeColor(sector.colors[[sector]],
length(annuli))
for (annulus in 1:(length(annuli) - 1)) {
drawSectorAnnulus(sector.edges[[sector]], sector.edges[[sector +
1]], annuli[annulus], annuli[annulus + 1],
annulus.colors[annulus])
}
}
}
else {
if (is.null(sector.colors))
sector.colors <- rainbow(nsectors)
for (sector in 1:nsectors) {
drawSectorAnnulus(sector.edges[sector], sector.edges[sector +
1], 0, radial.extents[sector], sector.colors[sector])
}
}
if (show.grid.labels) {
if (show.grid.labels%%2) {
ypos <- grid.pos - radial.lim[1]
xpos <- rep(0, length(grid.pos))
if (show.grid.labels == 1)
ypos <- -ypos
}
else {
xpos <- grid.pos - radial.lim[1]
ypos <- rep(0, length(grid.pos))
if (show.grid.labels == 2)
xpos <- -xpos
}
if (is.null(radial.labels))
radial.labels <- grid.pos
if (!is.null(grid.unit))
radial.labels[length(grid.pos)] <- paste(radial.labels[length(grid.pos)],
grid.unit)
if (boxed.radial)
boxed.labels(xpos, ypos, radial.labels, border = FALSE,
cex = par("cex.lab"))
else text(xpos, ypos, radial.labels, cex = par("cex.lab"))
}
invisible(oldpar)
}
这是输出:
radial.pie.alt(pie2,labels=letters[2:10], ylab="", xlab="")