dat <- data.frame(table(total$Name, total$Color))
# adds the Count column
names(dat) <- c("Name","Color","Count")
NAME COLOR Count
John Green 1
Joe Green 12
Jane Green 32
Jill Green 34
John Blue 2
Joe Blue 4
Jane Blue 23
Jill Blue 12
John Red 4
Joe Red 42
Jane Red 36
Jill Red 15
如何按名称创建一组多面饼图?当我尝试时:
e <- ggplot(data=dat, aes(x=Name, fill=Color))
e + geom_bar(position = "fill") +
facet_wrap(~Name) +
coord_polar()
它产生的饼图只是线条。任何人都可以识别错误或提供任何解决方案吗?
答案 0 :(得分:2)
x
中的aes
设置为静态值。我选择了0。theta
=“ y” to
coord_polar`以告诉它以角度使用哪个轴。scale_fill_identity()
,因为您已将颜色直接映射到填充值中。theme_void()
以摆脱混乱的轴等。library(tidyverse)
dat <- tribble(~Name,~Color,~Count,
"John", "Green", 1,
"Joe" , "Green", 12,
"Jane", "Green", 32,
"Jill", "Green", 34,
"John", "Blue", 2,
"Joe" , "Blue", 4,
"Jane", "Blue", 23,
"Jill", "Blue", 12,
"John", "Red", 4,
"Joe" , "Red", 42,
"Jane", "Red", 36,
"Jill", "Red", 15)
ggplot(data=dat, aes(x = 0, y = Count, fill=Color)) +
geom_col(position = "fill") +
facet_wrap(~Name) +
coord_polar(theta = "y") +
scale_fill_identity() +
theme_void()
由reprex package(v0.2.1)于2018-11-14创建