How to make a geom_scatterpie

I'm trying to make a pie chart of fish species and the number of fish, but I can't get the radius right.

My data:

enter image description here

I run this without specific radius:

ggplot()+ geom_scatterpie(data=Data_longlat,aes(x=Longitude, y=Latitude), alpha=0.5, cols = c("Abbor", "Laue", "Harr","Mort","Sik", "Stingsild", "Vederbuk", "Steinsmett", "Orekyt","Orret", "Hork", "Lagesild", "Gjedde", "Brasme", "Karpefisk", "Karuss","Krokle","Karpefisk 0+"), color=NA) + coord_equal() 

And get this (picture 2). It looks great, but I want the size of the pie to be equal to the number of total fish.

enter image description here

When I try to specify the radius I get all the pie charts merged together ??

ggplot()+ geom_scatterpie(data=Data_longlat, aes(x=Longitude, y=Latitude, r=Totalt), alpha=0.5, cols = c("Abbor", "Laue", "Harr","Mort","Sik", "Stingsild", "Vederbuk", "Steinsmett", "Orekyt","Orret", "Hork", "Lagesild", "Gjedde", "Brasme","Karpefisk", "Karuss","Krokle","Karpefisk 0+"), color=NA) + coord_equal() 

enter image description here

Upvotes: 1

Views: 3065

Answers (1)

Adam Quek
Adam Quek

Reputation: 7153

I suspect that the radius provide the product for each piechart, blowing them out of the latitude and longitude limits. This is evident from how your range of lat-long increase by more than 5 fold it's original range.

Playing around with the multiplying the radius input with a smaller constant will give you what you wanted. Here's a toy example:

library(tidyverse); library(scatterpie)
set.seed(4)
long <- rnorm(20, 10.8, sd=0.25)
lat <- rnorm(20, 60.7, sd=0.17)
d <- data.frame(long=long, lat=lat)
n <- nrow(d)
d$region <- factor(1:n)
d$A <- sample(0:50, n, replace=TRUE)
d$B <- sample(0:50, n, replace=TRUE)
d$C <- sample(0:50, n, replace=TRUE)
d$D <- sample(0:50, n, replace=TRUE)
d <- d %>% mutate(total = A + B + C + D)

# taking the total as is
ggplot()+ 
  geom_scatterpie(data = d, 
                  aes(x=long, y=lat, r=total), 
                  alpha=0.5, 
                  cols = c("A", "B", "C", "D"), color=NA) + 
  coord_equal() 

enter image description here

#multiply the radius by a constant of 0.00035

ggplot()+ 
  geom_scatterpie(data = d, 
                  aes(x=long, y=lat, r=0.00035*(total)), 
                  alpha=0.5, 
                  cols = c("A", "B", "C", "D"), color=NA) + 
  coord_equal() 

enter image description here

Upvotes: 3

Related Questions