簡體   English   中英

如何從plotrix包中刪除徑向餅圖中的0?

[英]How to remove the 0 in a radial pie chart from plotrix package?

我想用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”旁邊。 任何想法刪除它?

看起來像參數xlabylab永遠不會在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="")

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM