我已经关注了上一个帖子ggplot Donut chart
中的代码然而,当显示所述'甜甜圈图'时,R得出一个饼图。我如何获得圆环图?
我是R和ggplot的新手。
## add columns for drawing with geom_rect
microcolour.df$Percentage = microcolour.df$Freq / sum(microcolour.df$Freq)*100
microcolour.df = microcolour.df[rev(order(microcolour.df$Percentage)), ]
microcolour.df$ymax = cumsum(microcolour.df$Percentage)
microcolour.df$ymin = c(0, head(microcolour.df$ymax, n=-1))
microcolour.df
## reorder colour levels
print(levels(microcolour.df$Colour))
microcolour.df$Colour <- reorder(microcolour.df$Colour,
new.order = c(10, 1, 9, 5, 2, 11, 4, 8, 7, 6, 3))
## create donut
ggplot(microcolour.df, aes(fill = Colour, ymax = ymax, ymin = ymin, xmax = 100, xmin = 0)) +
geom_rect(colour = "black") +
coord_polar(theta = "y") +
xlim(c(0, 100)) +
theme(panel.grid=element_blank()) +
theme(axis.text=element_blank()) +
theme(axis.ticks=element_blank())
非常感谢任何帮助或智慧的话语。在我绕过这一点后,我会修改颜色等。
谢谢。