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
Since the plot is circular, it can be easily done by circlize package.
First the data:
Category <- c("Electronics", "Appliances", "Books", "Music", "Clothing",
"Cars", "Food/Beverages", "Personal Hygiene",
"Personal Health/OTC", "Hair Care")
Percent <- c(81, 77, 70, 69, 69, 68, 62, 62, 61, 60)
color = rainbow(length(Percent))
Reverse the three vectors since circlize adds each element from inside to outside by default:
Category = rev(Category)
Percent = rev(Percent)
color = rev(color)
If you image the circle is a bent plot region, then it is just adding rectangles, lines and texts.
library(circlize)
par(mar = c(1, 1, 1, 1))
circos.par("start.degree" = 90)
circos.initialize("a", xlim = c(0, 100)) # 'a` just means there is one sector
circos.trackPlotRegion(ylim = c(0.5, length(Percent)+0.5), track.height = 0.8,
bg.border = NA, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim") # in fact, it is c(0, 100)
for(i in seq_along(Percent)) {
circos.lines(xlim, c(i, i), col = "#CCCCCC")
circos.rect(0, i - 0.45, Percent[i], i + 0.45, col = color[i],
border = "white")
circos.text(xlim[2], i, paste0(Category[i], " - ", Percent[i], "%"),
adj = c(1, 0.5))
}
})
circos.clear()
text(0, 0, "GLOBAL", col = "#CCCCCC")
