3

Currently I am working on report with a floating pie chart as one of the plots. Currently I use the plotrix package to plot this pie chart. But since I use ggplot2 for all the other plots, the pie plot looks different. So I'm trying to create the plot using ggplot2. Currently I have two issues:

  1. The ggplot pie charts are plotted on a polar coordination system. I want to plot multiple pie charts on Cartesian coordination system. At the moment I do not know how to do this.

  2. I want to be able to control the pie radius on the Cartesian coordination system.

Here is the code I currently use:

library("plotrix")
plot(1:5, type="n", xlab="x", ylab="y")
floating.pie(2, 3, c(1,3,5), radius=0.5)
floating.pie(4, 2, c(2,4), radius=0.2)
floating.pie(4.5, 4, c(3,2,5,1), radius=0.3)

Thanks for your time and help.

csgillespie
  • 59,189
  • 14
  • 150
  • 185
jeroen81
  • 2,305
  • 5
  • 29
  • 41
  • 1
    http://stackoverflow.com/questions/9233077/r-how-to-overlay-pie-charts-on-dots-in-a-scatterplot-in-r ; also, this conversation http://groups.google.com/group/ggplot2/browse_thread/thread/b1f81cf870202e2c/f1a60b0c16a2f62a?pli=1 which suggests that `geom_pie` (or `geom_wedge` as suggested by Hadley Wickham) don't yet exist ... – Ben Bolker Mar 13 '12 at 13:45
  • Thanks, I think my request is not feasible at this moment. I just keep using the plotrix package. – jeroen81 Mar 14 '12 at 18:02
  • In this blog post I found a nice solution: http://ygc.name/2015/08/31/subview/ – jeroen81 Sep 01 '15 at 08:35

2 Answers2

5
  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")
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
2

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

rankthefirst
  • 1,370
  • 2
  • 14
  • 26
  • 1
    IME scatterpie is very fiddly. Being forced to use `coord_fixed` in particular is a tremendous hindrance. – flies Apr 23 '20 at 18:20