有什么方法可以在地图上绘制多个条形图?

Any way to plot multiple barplots on a map?

我正在尝试在地图上绘制多个条形图,我只是在寻找一个起点。我已经看过几个问题(如下所示)..

Barplots on a Map

Plotting bar charts on map using ggplot2?

然而,所有这些似乎都过时了。

下面是我试图绘制的数据。我希望在一张地图上绘制 4 个地块,每个地理位置一个。我希望每个地块都是每个位置的每个目的的计数的 barpot。

                 geoloc                     purpose count
1      Eastern Atlantic                    Behavior     4
2      Eastern Atlantic           Impacts/Fisheries     7
3      Eastern Atlantic                   Knowledge     8
4      Eastern Atlantic Migration/Habitat Selection     2
5      Eastern Atlantic                    Movement    10
7       Eastern Pacific                    Behavior     1
8       Eastern Pacific           Impacts/Fisheries     1
9       Eastern Pacific                   Knowledge     3
10      Eastern Pacific Migration/Habitat Selection     2
11      Eastern Pacific                    Movement     4
13 Southwestern Pacific                    Behavior     3
14 Southwestern Pacific                    Movement     7
15     Western Atlantic                    Behavior     8
16     Western Atlantic           Impacts/Fisheries     2
17     Western Atlantic                   Knowledge     8
18     Western Atlantic Migration/Habitat Selection     3
19     Western Atlantic                    Movement     9

这就是我获得我正在尝试使用的地图的方式

mp <-  NULL
mapWorld <- borders("world", colour="gray70", fill="gray70") 
mp <- ggplot() +   mapWorld

我希望能够在 ggplot2/ggmap 中执行此操作,因为我已经习惯了,但很乐意学习其他解决方案!

这类似于我正在尝试做的事情(来自 Memarzadeh 等人,2019 年)。

我个人会使用 magick 包将图形视为图像,并将图像与所需的偏移量合并以创建类似于您的目标的东西。我创建了一个非常简单的示例,向您展示了如何在世界地图上放置两个条形图

显然,您可以执行进一步操作以添加图例、图表标题等。这是我使用的代码

library(ggmap)
library(maps)
library(ggplot2)
library(magick)
mp <-  NULL
mapWorld <- borders("world", colour="gray70", fill="gray70") 

fig <- image_graph(width = 850, height = 550, res = 96)
ggplot() + mapWorld
dev.off()

df1 <- data.frame(name = c('A','B','C'), value = c(10,12,13))
df2 <- data.frame(name = c('A','B','C'), value = c(8,12,18))

bp1 <- ggplot(df1, aes(x = name, y = value, fill = name)) +
  geom_bar(stat = 'identity') +
  theme_bw() + 
  theme(legend.position = "none", axis.title.x = element_blank(), axis.title.y = element_blank())

bp2 <- ggplot(df2, aes(x = name, y = value, fill = name)) +
  geom_bar(stat = 'identity') +
  theme_bw() +
  theme(legend.position = "none", axis.title.x = element_blank(), axis.title.y = element_blank())

barfig1 <- image_graph(width = 100, height = 75, res = 72)
bp1
dev.off()

barfig2 <- image_graph(width = 100, height = 75, res = 72)
bp2
dev.off()

final <- image_composite(fig, barfig1, offset = "+75+150")
final <- image_composite(final, barfig2, offset = "+325+125")
final