带有 R ggplot2 的多个饼图

Gen*_*100 1 r ggplot2 pie-chart

我以前使用带有如下表格的 facet wrap 制作了多个折线图,但由于某种原因,我对饼图做同样的事情不太走运;

test <- data.frame(CONFIDENCE = c(rep("Mconfid", 3), rep("Hconfid", 3), rep("SHconfid", 3)),
                 POPULATION = c(rep(c("African","East_Asian","European"),3)),
                 AMOUNT = c(0.06, 0.23, 0.71, 0.00, 0.40, 0.60, 0.00, 0.10, 0.90))
test

  CONFIDENCE POPULATION AMOUNT
1    Mconfid    African   0.06
2    Mconfid East_Asian   0.23
3    Mconfid   European   0.71
4    Hconfid    African   0.00
5    Hconfid East_Asian   0.40
6    Hconfid   European   0.60
7   SHconfid    African   0.00
8   SHconfid East_Asian   0.10
9   SHconfid   European   0.90
Run Code Online (Sandbox Code Playgroud)

我想要 3 个饼图来使用 ggplot2 在“CONFIDENCE”上进行分面包装或网格

谢谢

如果有人想做多个折线图,这对我有用:

ggplot(test, aes(x=POPULATION, y=AMOUNT, group=CONFIDENCE, color=CONFIDENCE)) + geom_line() + facet_wrap(~ CONFIDENCE)
Run Code Online (Sandbox Code Playgroud)

m0n*_*awk 6

对于饼图,ggplot您需要设置x""然后添加coord_polar(主题只是删除值)。

ggplot(data, aes(x="", y=AMOUNT, group=POPULATION, color=POPULATION, fill=POPULATION)) +
  geom_bar(width = 1, stat = "identity") +
  coord_polar("y", start=0) + facet_wrap(~ CONFIDENCE) +
  theme(axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid  = element_blank())
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明

  • 也许也更关心你的听众 https://github.com/hrbrmstr/waffle (2认同)