我在 ggplot 中的饼图有问题。这是代码的示例。
library(ggplot2)
library(scales)
overtime.by.dow <- structure(list(dow = structure(c(2L, 2L, 3L, 3L, 4L, 4L, 5L,
5L, 6L, 6L), .Label = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
"Sat"), class = "factor"), Overtime = structure(c(1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("FALSE", "TRUE"), class = "factor"),
Freq = c(2L, 48L, 0L, 51L, 0L, 50L, 0L, 50L, 44L, 6L), Percent = c(4,
96, 0, 100, 0, 100, 0, 100, 88, 12), Per.txt = c("2\n4%",
"48\n96%", "0\n0%", "51\n100%", "0\n0%", "50\n100%", "0\n0%",
"50\n100%", "44\n88%", "6\n12%"), txt.pos = c(2, 52, 0, 50,
0, 50, 0, 50, 44, 94), cumsum = c(4, 100, 0, 100, 0, 100,
0, 100, 88, 100)), .Names = c("dow", "Overtime", "Freq",
"Percent", "Per.txt", "txt.pos", "cumsum"), row.names = c(2L,
9L, 3L, 10L, 4L, 11L, 5L, 12L, 6L, 13L), class = "data.frame")
ggplot(data = overtime.by.dow,
aes(x="",
y=Percent,
fill = Overtime)) +
geom_bar(width = 1) +
facet_wrap(~dow) +
xlab('') +
geom_text(aes(y = txt.pos, label = Per.txt)) +
coord_polar(theta = "y") +
scale_fill_manual(values = c('green', 'red'))
我收到以下错误。我认为问题是因为我有一些 100% 的馅饼。代码将成为自动过程的一部分,100% 的馅饼很可能,我确实想展示它们。有没有什么技巧可以让你拥有 100% 的馅饼?
Error in lf$dist[idx] <- spiral_arc_length(lf$slope[idx], lf$tn1[idx], :
NAs are not allowed in subscripted assignments