你能在 R 中将 geom_bar 饼图组合到 geom_point 图上吗?

Can you combine a geom_bar pie over a geom_point plot in R?

有没有办法在 geom_point 情节上绘制 geom_pie?使用共享变量(此处:位置)

我见过有人在地图上做馅饼plotting pie graphs on map in ggplot

但是我想知道是否有一些包或函数可以让你这样做?

这是我的数据和两个当前图:

data_point <- data.frame(
  Location=(1:7),
  Var1=c(13,8, 6,5,4,2,1),
  Var2 = c(7,8,9,10,11,12,13))

data_pie <- data.frame(
  Location=rep(1:7,5),
  Group= c(rep("A",7),rep("B",7),rep("C",7),rep("D",7),rep("E",7)),
  value=c(45.59,63.56,66.47,58.60,67.28,44.45,9.22,0.00,0.00,0.00,0.00,0.00,4.14,37.81,0.00,0.00,0.00,0.04,
0.03,25.15,34.58,52.86,35.61,24.66,26.13,18.98,12.71,6.61,2,1,9,15,14,14,12))

a<-ggplot(data_point, aes(Var1, Var2, label=1:7)) + 
  geom_point(size = 3, stroke = 2)+
  theme_classic()
b<- ggplot(data_pie, aes(x="", y=value, fill=Group)) +
  geom_bar(stat="identity", width=1) +
  coord_polar("y", start=0) +
  facet_wrap(~Location)+ scale_fill_brewer(palette="Dark2")
ggarrange(a,b, nrow = 1)

想要的情节:

这是 scatterpie 包中 geom_scatterpie 的想法:

加入数据

df <- data_pie %>% 
  pivot_wider(id_cols = Location,
              names_from = Group, 
              values_from =  value) %>% 
  left_join(data_point, by = "Location")

代码

library(scatterpie)

ggplot() +
  geom_scatterpie(data = df, aes(x = Var1, y = Var2,
                      group = Location), 
                  cols = c("A", "B", "C", "D", "E"))

情节