YuLab-SMU / scatterpie

:art: scatter pie plot
https://cran.r-project.org/package=scatterpie
60 stars 15 forks source link

Support for long-form data #13

Open rjake opened 6 years ago

rjake commented 6 years ago

Very cool to find this package as I'm trying to make some maps with proportional pie charts. Is it possible to get this to use data that has a categorical variable in single column? The example below should generate a reproducible example (although not on a map)

library(tidyverse)
library(scatterpie)

iris_pie <-
    iris %>%
    mutate(Species = as.character(Species),
           x = ntile(Petal.Length, 4),
           y = ntile(Sepal.Width, 4)) %>% 
    group_by(Species, x, y) %>% 
    summarise(n = n()) %>% 
    group_by(x, y) %>% 
    mutate(total = sum(n)) %>% 
    ungroup()

ggplot(iris_pie) +
    geom_point(aes(x, y, size = total))

ggplot() +
    geom_scatterpie(data = iris_pie, aes(x, y, radius = total)) #slice = n??

I would like to see these split into sections by the various Species represented.

make_pies

The data looks like this pie_df

timcashion commented 5 years ago

Seconded!