我正在尝试将百分比标签添加到圆环图中,但在绘制明确的百分比值表示(圆形而非重叠)方面未能成功
## my data
library(ggplot2)
col <- c("white", "black", "transparent", "grey", "blue", "yellow", "green", "red", "pink", "orange", "brown")
freq <- c(101, 68, 34, 18, 14, 5, 5, 3, 2, 1, 1)
## create data frame
colour.df <- data.frame(col, freq)
colour.df
## calculate percentage
colour.df$percentage = colour.df$freq / sum(colour.df$freq)* 100
colour.df = colour.df[rev(order(colour.df$percentage)), ]
colour.df$ymax = cumsum(colour.df$percentage)
colour.df$ymin = c(0, head(colour.df$ymax, n = -1))
colour.df
## reorder colour levels
colour.df$col <- reorder(colour.df$col,
new.order = c(10, 1, 9, 5, 2, 11, 4, …Run Code Online (Sandbox Code Playgroud)