如何在R中必要时创建带插图的Choropleth世界地图

问题描述

我希望创建带有区域显示在世界地图上几乎看不到的小区域的choropleth世界地图。以下是我要绘制的那种世界地图的示例:

enter image description here

上图来自《长矛》中的一篇文章"Global,regional,and national age-sex-specific mortality for 282 causes of death in 195 countries and territories,1980–2017: a systematic analysis for the Global Burden of Disease Study 2017".在此图中,在世界地图下方,许多小区域的插图被放大。

我可以在R中创建世界地图,但是只能创建没有插图的大型地图。但是我想问一下是否有R代码可为这些较小的位置创建插图?

解决方法

我认为最好的策略是单独制作图,然后将它们拼接在一起。这是一个简单又肮脏的例子。

public class PostCategory 
{
    public string Category { get; set; }
    public int Count { get; set; }
}

public async Task<IList<PostCategory>> GetRecentPostsAsync()
{
    return await _db.Posts
        .Where(e => e.Published.HasValue && e.Published.Value <= DateTime.Today && e.Category != "Sell")
        .GroupBy(x => x.Category)
        .Select(y => new { Category = y.Key,Count = y.Count() })
        .ToListAsync();
}

reprex package(v0.3.0)于2020-11-03创建

要使图很好地平铺,必须确保所有插图都具有正确的宽高比。您可以通过相应地设置插图的x和y限制来做到这一点。我在此处设置了非投影坐标的限制,以便快速组合,但是通过在投影坐标中设置限制,您将可以更好地控制确切的宽高比(无论如何,这是您在当前发布的ggplot2版本中唯一可以做的事情)。