1

I have seen the answer Pie charts in geom_scatterpie overlapping.

But I do not want to reset the overlapped pie chart coordinate manually.

Is there some function in ggplot2 or something else can avoid overlap in geom_scatterpie() function?

Any help will be highly appreciated!

Reproducible code is at here:

library(scatterpie)
library(tidyverse)
library(geosphere)
library(ggnewscale)


us <- map_data('state') %>% as_tibble()

n = length(unique(us$region))

# creat fake mapping data

temperature_data <- tibble(region = unique(us$region),
                           temp = rnorm(n = n))

coords <- us %>% select(long, lat, region) %>% distinct(region, .keep_all = T)

category_data <- tibble(region = unique(us$region),
                        cat_1 = sample(1:100, size = n),
                        cat_2 = sample(1:100, size = n),
                        cat_3 = sample(1:100, size = n)) %>% left_join(coords)

us <- left_join(us, temperature_data)

p + 
  geom_map(map = us, aes(map_id = region, fill = temp), color = 'grey') +
  new_scale('fill') +
  geom_scatterpie(data = category_data,
                  aes(long, lat),
                  cols = c("cat_1", "cat_2", "cat_3"), 
                  alpha = 0.5)

zhiwei li
  • 1,635
  • 8
  • 26

0 Answers0