-1

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"))) %>% 
  arrange(KOMNAVN)


Bornholm <- geo %>% 
  filter(KOMNAVN=="Bornholm")

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"))
mainland 
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

closed as unclear what you're asking by Spacedman, whyzar, neogeomat, Jochen Schwarze, ahmadhanb Feb 1 at 11:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How far have you got in trying? Is it not working? Does it look wrong? Error messages? – Spacedman Jan 31 at 8:26
  • @ Spacedman: I do not know what projection to use. I have added some code to my question. – David Jan 31 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. – David Jan 31 at 8:59
1

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.

library(grid)

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. – David Jan 31 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 at 11:37
  • @ Spaceman: I got your message too late. Can we keep this post. The title is still relevant. – David Jan 31 at 11:41
  • @ Spacedman: I have changed it back. – David Jan 31 at 11:53

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