- library(tidyverse)
- dat = tibble(
- count = c(72.5, 6.3, 11.1, 10.1),
- category=c("BA", "Gini", "MAT", "PH"))
- # Add addition columns, needed for drawing with geom_rect.
- dat1 = dat %>%
- mutate(fraction = count / sum(count),
- category = factor(category, levels = c("BA","Gini","MAT","PH"))) %>%
- arrange(category) %>%
- mutate(ymax = cumsum(fraction), ymin = c(0, ymax[-n()]),
- labelPosition = (ymin + ymax) / 2,
- label = str_c(category, ":\n", round(fraction, 3) * 100, "%"))
- ggplot(dat1, aes(fill=category, ymax=ymax, ymin=ymin, xmax=5, xmin=2.8)) +
- geom_rect(color = "grey30") +
- coord_polar(theta = "y") +
- xlim(c(0, 5)) +
- scale_fill_manual(values = c("#8DD3C7", "#1F78B4","#33A02C","#E41A1C")) +
- theme_bw() +
- theme(panel.grid = element_blank()) +
- theme(axis.text = element_blank()) +
- theme(axis.ticks = element_blank()) +
- labs(title = "Young_A") +
- geom_label(x = 5, aes(y = labelPosition, label = label), size = 8) +
- theme(legend.position = "none")
说到 R语言知识汰旧换新、更新换代,看我免费分享的课件就足够了:[学习分享] 张敬信:分享我的1393页《R语言编程:基于tidyverse》完整课件


雷达卡



京公网安备 11010802022788号







