create floating pie charts with ggplot

烂漫一生 提交于 2019-12-04 13:02:36
  1. Pie charts by definition use polar coordinates. You could overlay some pie charts on another graph that used Cartesian coordinates but it would probably be awful. In fact, pie charts are mostly awful anyway, so be careful what you wish for.

  2. An example on the coord_polar page.

The important bit in that code is specifying that radius maps to the "y" aesthetic.

 df <- data.frame(
   variable = c("resembles", "does not resemble"),
   value = c(80, 20)
 )
ggplot(df, aes(x = "", y = value, fill = variable)) + 
  geom_bar(width = 1, stat = "identity") + 
  scale_fill_manual(values = c("red", "yellow")) + 
  coord_polar("y", start = 2 * pi / 3) +    #<- read this line!
  ggtitle("Pac man")

I had the same issue, there is a package called scatterpie based on ggfore solving the problem.

It's on cran, and you can see the examples here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!