I have the bounderies for the municipalities in the "capital region" of Denmark. The acctual map looks like this:

enter image description here

The yellow island is the fourth row in my sf object.

enter image description here

I am trying to folllow the example at the end of section 8.2.7 in this book (link). That is I need to make the yellow island smaller and move it closer to the rest. Also there seems not to be any tags for tmap, but that is the package the link uses.

I have tried this code:

RH <- geo %>%
  filter(REGIONKODE=="1084") %>% 
  select(KOMNAVN, AREAL)  %>% 
  filter(!(KOMNAVN  %in% c("Christiansø", "Bornholm"))) %>% 

Bornholm <- geo %>% 

mainland <-  tm_shape(RH, projection = 2163) + tm_polygons() + 
  tm_layout(frame = FALSE)  

Bornholm_map   <-  tm_shape(Bornholm) + tm_polygons() + 
  tm_layout(title = "Bornholm", frame = FALSE, bg.color = NA, 
            title.position = c("LEFT", "BOTTOM"))
print(Bornholm_map, vp = viewport(x = 0.35, y = 0.1, width = 0.2, height = 0.1))

This just rotates the plot with 90 dergrees and the island gets lost and I get this error message

Error in viewport(x = 0.35, y = 0.1, width = 0.2, height = 0.1) : 
  could not find function "viewport"

enter image description here

  • How far have you got in trying? Is it not working? Does it look wrong? Error messages?
    – Spacedman
    Jan 31 '19 at 8:26
  • @ Spacedman: I do not know what projection to use. I have added some code to my question.
    – xhr489
    Jan 31 '19 at 8:43
  • @ Spacedman: The question has been updated. I think the problem is the error could not find function "viewport. Also I am not able to install the package spDataLarge with my version of r.
    – xhr489
    Jan 31 '19 at 8:59

If you search for the word "viewport" in that text you'll see this:

Finally, we combine the two maps. A viewport from the grid package can be used by stating a center location (x and y) and a size (width and height) of the inset map.


So do library(grid) to bring in the viewport function.

  • @ Thanks Spaceman. I am going to update the question. I have a new problem which is that the legend colors don't seem to be correct for the island.
    – xhr489
    Jan 31 '19 at 11:35
  • Okay but that's a new question, not really an update. This question should really be called "Could not find "viewport" function". Keep things minimal.
    – Spacedman
    Jan 31 '19 at 11:37
  • @ Spaceman: I got your message too late. Can we keep this post. The title is still relevant.
    – xhr489
    Jan 31 '19 at 11:41
  • @ Spacedman: I have changed it back.
    – xhr489
    Jan 31 '19 at 11:53

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