如何调整 rworldmap 中的图例长度?

How to adjust the legend length in rworldmap?

我想调整rworldmap的图例栏。

    mapCountryData(df, 
                   nameColumnToPlot="users",
                   xlim=NA,
                   ylim=NA,
                   mapRegion="World",
                   numCats=30,
                   catMethod="pretty",
                   addLegend=TRUE,
                   mapTitle="map1",
                   colourPalette=c("heat")) 
    do.call(addMapLegend, c(mapParams, legendLabels="all",
                           legendWidth=0.5,
                           legendIntervals="data",
                           legendMar=2))     

我能够生成地图,但无法调整图例栏。图例布局横跨整个地图,看起来不太好。

Error in do.call(addMapLegend, c(mapParams, legendLabels = "all", legendWidth = 0.5, : object 'mapParams' not found

我无法提供数据集。任何人都可以帮助查看我的脚本的哪一部分产生了错误,我该如何解决?谢谢。

尝试将 mapParams <- 添加到第一行的开头。

另请查看包 tmap,它比 rworldmap 多 up-to-date。

更一般地说,Whosebug 建议您创建一个小的 'reproducible' 示例,这样人们就可以重新创建您的问题并测试解决方案。

祝你好运。

mapParams <- mapCountryData(df, 
                   nameColumnToPlot="users",
                   xlim=NA,
                   ylim=NA,
                   mapRegion="World",
                   numCats=30,
                   catMethod="pretty",
                   addLegend=TRUE,
                   mapTitle="map1",
                   colourPalette=c("heat")) 

do.call(addMapLegend, c(mapParams, legendLabels="all",
                       legendWidth=0.5,
                       legendIntervals="data",
                       legendMar=2))