问题
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