我正在尝试在一张地图上绘制多个条形图,只是在寻找一个开始的地方。我已经看过几个问题了(如下所示)。
Plotting bar charts on map using ggplot2?
How to plot barchart onto ggplot2 map
然而,所有这些似乎都过时了。
下面是我正在尝试绘制的数据。我希望在一张地图上制作4个地块,每个地理位置一个。我希望每一块地都是每个不同地点的不同目的的计数。
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年)。

发布于 2019-12-20 01:06:24
我个人会使用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")
finalhttps://stackoverflow.com/questions/59413256
复制相似问题