How to change map.scale line width from package maps?

I use map.scale() from the maps package to create a scale on the map. The following code creates an example of what I'm looking for:

 library(maps) png("example.png", width = 6000, height = 6000) map(database = "world", regions = 'Brazil',fill = T) map.scale(-43, -30, ratio = F, cex = 9, lheight= 1, pos =1, offset = 1) dev.off() 

When I create a high resolution png image, the line width of the created scale does not fit. You can check it by zooming in the lower right corner of the map.

Is there any parameter that I am missing to increase the width of the scale?

+4
source share
1 answer

The reason you cannot change the line width (this is the lwd argument you should look for here, not the line height here) is because it is not applied in the map.scale() function and passed to lines() call this part of the scale. We can, however, programmatically add this functionality to the function by doing something like this:

 library(maps) t <- capture.output(map.scale) ## Strip trailing text: t <- t[-length(t)] ## Find lines() call and add in a line width argument: t <- gsub("(lines\\(linexy)", "\\1, lwd=lwd", t) t <- gsub("(\\.\\.\\.)", "\\1, lwd=10", t) t <- paste(t, collapse="\n") eval( parse(text=paste0( "map.scale.new <- ", t )) ) ## Use our new map.scale.new() function with lwd= parameter: png("example.png", width = 6000, height = 6000) map(database = "world", regions = 'Brazil',fill = T) map.scale.new( -43, -30, ratio = F, cex = 9, lwd= 10, pos =1, offset = 1 ) dev.off() 

You can change lwd= to suit your fantasies.

enter image description here

+5
source

All Articles