如何用GEOM_MAP用各自的国旗填充国家?
我正在使用软件包ggplot2
,并使用函数geom_map
to 填充
具有不同颜色的国家。
我想知道是否可以用标志而不是颜色填充?
所需结果:
我正在做:
ALL_EU <-c("Russia", "Germany", "UK", "France", "Italy", "Spain", "Ukraine", "Poland", "Romania", "Netherlands", "Belgium", "Czech Republic", "Greece", "Portugal", "Sweden", "Hungary", "Belarus", "Austria", "Serbia", "Switzerland", "Bulgaria", "Denmark", "Finland","Slovakia", "Norway", "Ireland", "Croatia", "Moldova", "Bosnia and Herzegovina","Albania", "Lithuania", "North Macedonia", "Slovenia", "Latvia", "Estonia","Montenegro", "Luxembourg" , "Malta", "Iceland", "Andorra", "Monaco", "Liechtenstein","San Marino", "Vatican", "Kosovo")
#Filter some regions out just for plot
world_map <- map_data("world",region = ALL_EU[-which(ALL_EU%in%c("Russia","Iceland"))])
world_map <- world_map%>%filter(subregion!="Svalbard"&subregion!="Jan Mayen"|is.na(subregion))
然后绘制它,请注意,在这种情况下,我使用fill = “标志”
因此,我可以用scale_fill_manual
更改颜色和传奇,也可以使所有国家/地区蓝色仅用于一个可复制的示例。
ggplot() +
theme_void()+
geom_map(dat = world_map,map = world_map,
aes(map_id = region,fill = "Flags"),color = "gray",size = 0.25)+
scale_fill_manual(name = "Countries", values = c("Flags" = "blue"))+
expand_limits(x = world_map$long, y = world_map$lat)
也,即使可能,也可以将几个国家填满,例如欧盟的旗帜。但这可能是另一个问题。谢谢你!
I'm working with package ggplot2
and using the function geom_map
to fill
the countries with different colors.
I was wondering if it is possible to fill with flags instead of colors?
Desired result:
I'm doing:
ALL_EU <-c("Russia", "Germany", "UK", "France", "Italy", "Spain", "Ukraine", "Poland", "Romania", "Netherlands", "Belgium", "Czech Republic", "Greece", "Portugal", "Sweden", "Hungary", "Belarus", "Austria", "Serbia", "Switzerland", "Bulgaria", "Denmark", "Finland","Slovakia", "Norway", "Ireland", "Croatia", "Moldova", "Bosnia and Herzegovina","Albania", "Lithuania", "North Macedonia", "Slovenia", "Latvia", "Estonia","Montenegro", "Luxembourg" , "Malta", "Iceland", "Andorra", "Monaco", "Liechtenstein","San Marino", "Vatican", "Kosovo")
#Filter some regions out just for plot
world_map <- map_data("world",region = ALL_EU[-which(ALL_EU%in%c("Russia","Iceland"))])
world_map <- world_map%>%filter(subregion!="Svalbard"&subregion!="Jan Mayen"|is.na(subregion))
and then plot it, note that in this case I use fill = "Flags"
so I can then change the color and legend with scale_fill_manual
, also I make all countries blue just for a reproducible example.
ggplot() +
theme_void()+
geom_map(dat = world_map,map = world_map,
aes(map_id = region,fill = "Flags"),color = "gray",size = 0.25)+
scale_fill_manual(name = "Countries", values = c("Flags" = "blue"))+
expand_limits(x = world_map$long, y = world_map$lat)
Also, and even if its possible, fill several countries with, for example, the flag of the European Union. But this is probably for another question. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个选项,使用优点
ggpattern
和flagon
软件包。Here is an option using the excellent
ggpattern
andflagon
packages.