我已经使用ggplot准备了靶心图。但是我有一个洞。如何将其删除并获得完整的一个?

r - ggplot2中的靶心孔-LMLPHP

critters <- structure(list( a = 15, b = 47, c = 22, d=9, e=7), .Names = c("a", "b", "c", "d", "e"), row.names = c(NA, -1L), class = "data.frame")

d <- data.frame(test=factor(c(rep("a", critters$a),
                            rep("b", critters$b),
                            rep("c", critters$c),
                            rep("d", critters$d),
                            rep("e", critters$e)),
                          levels = c("a", "b", "c", "d", "e"), ordered= TRUE))
levels(d$test) <- apply(data.frame(table(d$test)), 1, paste, collapse = ": ")

ggplot(d, aes(x = factor(1), fill = factor(test))) + geom_bar()+ coord_polar() + labs(x = NULL, fill = NULL) + scale_fill_manual(values = c("blue", "yellow", "green", "red", "magenta"))

最佳答案

您需要在width = 1中设置geom_bar

ggplot(d, aes(x = factor(1), fill = factor(test))) +
  geom_bar(width = 1) +
  coord_polar() +
  labs(x = NULL, fill = NULL) +
  scale_fill_manual(values = c("blue", "yellow", "green", "red", "magenta"))

关于r - ggplot2中的靶心孔,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37273340/

10-12 17:23