Making a circular barplot with a hollow center (aka race track plot)

前端 未结 4 792
滥情空心
滥情空心 2021-01-30 13:22

I was asked to recreate the following style of plot. (Please ignore the question of whether this is a good type of visualization and charitably consider this as adding a colorf

4条回答
  •  一生所求
    2021-01-30 14:03

    Here's a non-ggplot2 (base R graphics) solution using the plotrix package, which contains two nice functions: draw.circle() and draw.arc():

    circBarPlot <- function(x, labels, colors=rainbow(length(x)), cex.lab=1) {
      require(plotrix)
      plot(0,xlim=c(-1.1,1.1),ylim=c(-1.1,1.1),type="n",axes=F, xlab=NA, ylab=NA)
      radii <- seq(1, 0.3, length.out=length(x))
      draw.circle(0,0,radii,border="lightgrey")
      angles <- (1/4 - x)*2*pi
      draw.arc(0, 0, radii, angles, pi/2, col=colors, lwd=130/length(x), lend=2, n=100)
      ymult <- (par("usr")[4]-par("usr")[3])/(par("usr")[2]-par("usr")[1])*par("pin")[1]/par("pin")[2]
      text(x=-0.02, y=radii*ymult, labels=paste(labels," - ", x*100, "%", sep=""), pos=2, cex=cex.lab)
    }
    
    circBarPlot(Percent/100, Category)
    text(0,0,"GLOBAL",cex=1.5,col="grey")
    

    It gives me:

    Circular bar plot

提交回复
热议问题