且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有特定顺序和百分比注释的ggplot2饼图

更新时间:2023-11-26 12:04:16

You have to change levels of Make by share or volume (provided data is already sorted):

dfc$Make <- factor(dfc$Make, levels = rev(as.character(dfc$Make)))

And play with theme arguments:

ggplot(dfc[1:10, ], aes("", share, fill = Make)) +
    geom_bar(width = 1, size = 1, color = "white", stat = "identity") +
    coord_polar("y") +
    geom_text(aes(label = paste0(round(share), "%")), 
              position = position_stack(vjust = 0.5)) +
    labs(x = NULL, y = NULL, fill = NULL, 
         title = "market share") +
    guides(fill = guide_legend(reverse = TRUE)) +
    scale_fill_manual(values = c("#ffd700", "#bcbcbc", "#ffa500", "#254290")) +
    theme_classic() +
    theme(axis.line = element_blank(),
          axis.text = element_blank(),
          axis.ticks = element_blank(),
          plot.title = element_text(hjust = 0.5, color = "#666666"))

相关阅读

推荐文章