0

For my master thesis I would need to do a map (possibly with ggplot) with pie charts on it, I've read many threads about the library scatterpie but it doesn't work with my data. My data are something like this:

Long Lat Abundance Names
X Y 3 Jhonny
X Y 1 Manuel
X Y 2 Mike

Scatterpie function doesn't work because it asks that "the slices" of the pie are different columns of the data frame. Instead, I would need a pie in which the slices are each name of the Names column and the width of the slice that corresponds to the Abundance variable.

Is there a function that does this?

Daniel Molitor
  • 644
  • 4
  • 11
  • 2
    Could you not pivot your data into wide format to give `scatterpie` what it wants? – Limey Jun 15 '22 at 14:11
  • [Here's the FAQ for pivoting data from long to wide](https://stackoverflow.com/q/5890584/903061). Something like `tidyr::pivot_wider(your_data, names_from = Names, values_from = Abundance)` should do it. – Gregor Thomas Jun 15 '22 at 15:05
  • yes, this function changed my data into wide format but I still have problems with geom_scatterpie(). I'm using this code: ggplot() + geom_scatterpie(aes(x = long, y = lat), cols = c(22:25), data = my_data) + coord_fixed() the plot background appears but is blank and the console gives me the warning "Removed 4532 rows containing non-finite values (stat_pie)." – Aedan-1996 Jun 16 '22 at 17:28

0 Answers0