How to adjust the legend length in rworldmap?

我的未来我决定 提交于 2019-12-23 05:32:34

问题


I would like to adjust the legend bar of 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))     

I was able to generate the map, but failed to adjust the legend bar. The legend layout was across the map, which did not look well.

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

I am not able to provide the dataset. Can anyone help review which part of my scripts generates the error and how can I fix it? Thank you.


回答1:


Try adding mapParams <- to the start of your first line.

Also have a look at package tmap which is more up-to-date than rworldmap.

More generally, Stackoverflow recommends that you create a small 'reproducible' example, that would allow people to recreate your issue and test solutions.

Good luck.

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))


来源:https://stackoverflow.com/questions/49314761/how-to-adjust-the-legend-length-in-rworldmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!