1

在 geom_scatterpie 中看到了答案饼图重叠

但我不想手动重置重叠的饼图坐标。

ggplot2 中是否有某些功能或其他可以避免 geom_scatterpie() 功能重叠的功能?

任何帮助将不胜感激!

可重现的代码在这里:

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)

4

0 回答 0