Monday, 1 October 2018

sp - How to I limit the x and y axes with tmap in r


I have made this plot with the following code:


library(tmap)    
tm_shape(RH2) +

tm_fill(col="AREAL") +
tm_borders()

enter image description here


But there is a dot on the far right (an island) which I don't understand why it is there. Is there a way to limit the plot to avoid all the white spaces? like coord_fixed(xlim=c(7, 12), ylim=c(52, 58)) in ggmap?



Answer



Have you read the help for tm_shape? It gives the following parameter:


bbox: bounding box. One of the following:

• A bounding box (an ‘sf’ bbox object, see ‘st_bbox’, a 2

by 2 matrix (used by the ‘sp’ package), or an ‘Extent’
object used by the ‘raster’ package).

Its in map units rather than lat-long, so with the World data from the help you can do:


tm_shape(World, bbox=tmaptools::bb(matrix(c(0,0,2000000,2000000),2,2))) +tm_polygons()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...