I have made this plot with the following code:

tm_shape(RH2) +
      tm_fill(col="AREAL") +

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?

1 Answer 1


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()
  • 1
    @ Thanks spacedman. I will look at it tomorrow when I have my computer. But what is your take on sp vs sf objects?
    – xhr489
    Commented Jan 30, 2019 at 17:27
  • 1
    Use sf whenever possible.
    – Spacedman
    Commented Jan 30, 2019 at 22:28
  • 1
    @ Spacedman: How does one convert lon-lat units to map units?
    – xhr489
    Commented Feb 1, 2019 at 6:03
  • Its the same coordinates as the thing you have in the tm_shape function. If this is a thing in lat-long coordinates, then the map coordinates are also lat-long coordinates. But if you are working with maps in projected coordinates then you use those. see sp::spTransform or sf:st_transform for more.
    – Spacedman
    Commented Feb 1, 2019 at 7:51
  • @ Spacedman: Actually I don't think I need transforming. If I look at the "dots" geometry object and print it, the sf object prints the numbers I need for making the bbox. That is mysf_object$geometry[row_num]. But how can I get the bbox numbers for the main plot?
    – xhr489
    Commented Feb 1, 2019 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.