YuLab-SMU / scatterpie

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

Artefacts with overlapping pies #32

Open dramanica opened 3 years ago

dramanica commented 3 years ago

In some instances, ovelapping pies are clipped incorrectly. Here is a simple reproducible example:

df<-data.frame(lat=c(1,1.5),long=c(2,2.1),A=c(0.2,0.5),B=c(0.7,0.4),C=c(0.1,0.1))
ggplot()+geom_scatterpie(aes(x=long,y=lat),cols=c("A","B","C"),data=df,pie_scale=150)+coord_equal()

image

alexkrohn commented 2 years ago

I've found this same issue and haven't found a solution. From what I can tell it occurs because the colors are plotted sequentially instead of pies being plotted together (e.g. all green slices are plotted, then all red slices, then all blue slices, so the blues overlap the greens). I'm not sure how to remedy this.

@dramanica Did you find a solution to this?

dramanica commented 2 years ago

@alexkrohn No, I am afraid I never did find a proper solution; swapping the order of the factor levels can help depending on how the colours overlap (but that's a hack that will only work under some circumstances).

alexkrohn commented 2 years ago

Bummer. I love this package, but this error is forcing me back into base R. Thanks for looking into it, anyway!

dicorynia commented 1 year ago

Adding an id column and using it for grouping solves this issue

df <- data.frame(id = c(1, 2), 
                 lat=c(1,1.5),
                 long=c(2,2.1),
                 A=c(0.2,0.5),
                 B=c(0.7,0.4),
                 C=c(0.1,0.1))

ggplot()+
  geom_scatterpie(data=df,
                  aes(x=long,y=lat, group = id),
                  cols=c("A","B","C"),
                  pie_scale=150)+
  coord_equal()

image

GuangchuangYu commented 1 year ago

@xiangpin pls incorporate this feature (using .id internally) to the geom_scatterpie layer.