如何从plotrix包中删除径向饼图中的0 ?

时间:2022-01-25 13:42:15

I want to make a pie chart with radial.pie(). But on the left of the graph there is 0 and I would like to remove it.

我想做一个有弧度的饼图。但是在图的左边是0,我想把它去掉。

Code :

代码:

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])

This code give us this graph :

这段代码给了我们这个图:

如何从plotrix包中删除径向饼图中的0 ?

So you see 0 at the left of the graph, next to the label "f". Any ideas to remove it ?

所以你在图左边看到的是0,旁边是“f”有什么办法消除它吗?

1 个解决方案

#1


2  

Looks like the arguments xlab and ylab are never passed within the radial.pie function. Below is a modified version of the function (radial.pie.alt) where these arguments are passed successfully:

看起来参数xlab和ylab从未在径向中传递。派的功能。下面是一个修改后的函数(radi. pi .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)
}

And here is the output:

这是输出:

radial.pie.alt(pie2,labels=letters[2:10], ylab="", xlab="")

如何从plotrix包中删除径向饼图中的0 ?

#1


2  

Looks like the arguments xlab and ylab are never passed within the radial.pie function. Below is a modified version of the function (radial.pie.alt) where these arguments are passed successfully:

看起来参数xlab和ylab从未在径向中传递。派的功能。下面是一个修改后的函数(radi. pi .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)
}

And here is the output:

这是输出:

radial.pie.alt(pie2,labels=letters[2:10], ylab="", xlab="")

如何从plotrix包中删除径向饼图中的0 ?