1

The data for this example can be found here: https://github.com/davidbaniadam/maps

The problem is essentially the same with Alaska and mainland USA, i.e. I want the size of Alaska to be correct in relation to the other states. So I am creating this plot: enter image description here

But I want to keep the actual size of the "small island" with the text "Bornholms Hospital". How can I do that? I have also used the tmappackage but had problems with the labels (could not control them). The code is below. At the end I use print with viewport. Is there another way to combine two plots?

library(sf)
library(dplyr)
library(ggplot2)
library(stringr)
library(grid)

geo <-  st_read("ADM/KOMMUNE.shp") 

# This is my plot
geo_RH_sj <- geo %>%  
  filter(REGIONKODE=="1084")  %>% 
  filter(!stringr::str_detect(KOMNAVN,"Christians") & !str_detect(KOMNAVN, "Bornholm")) 


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


df <- data.frame(place = c("Skt. Lukas Stiftelsen", 
                           "Arresødal", 
                           "Diakonissestiftelsen", 
                           "Bornholms Hospital", 
                           "Søndergaard"), 
                 Y =   c(55.727444, 55.976848, 55.678323, 55.092019, 55.743852), 
                 X =   c(12.555917, 12.031369, 12.515989, 14.707619, 12.323568),
                 Antal = c(24, 12, 16, 2, 16)
)

df1 <- st_as_sf(df, coords = c("X", "Y"),  
                crs = 4326, 
                remove = FALSE, 
                agr = "constant")

mainland <- ggplot(data = geo_RH_sj) +
  geom_sf(fill= "#fecc5c", color = "#fecc5c") +
  geom_sf(data = df1) +
  geom_sf_label(data = df1, aes(label = place), nudge_x = c(2000, 0, 0, 0, 0), 
                nudge_y = c(2000, 2000, -2000, 0,  2000)) +
  coord_sf(xlim = c(677299.3, 739128.7), ylim = c(6162392.4, 6225395.8), expand = FALSE) +
  theme_void() +
  theme(panel.grid.major = element_line(color = "white"))


a <- st_bbox(geo_RH_bh)

bornholm <- ggplot(data = geo_RH_bh) +
  geom_sf(fill= "#fecc5c", color = "#fecc5c") +
  geom_sf(data = df1) +
  geom_sf_label(data = df1, aes(label = place), nudge_x = c(0, 0, 0, 15000, 0), 
                nudge_y = c(0, 0, 0, 2000,  0)) +
  coord_sf(xlim = a[c(1, 3)], ylim = a[c(2, 4)], expand = FALSE) +
  theme_void() +
  theme(panel.grid.major = element_line(color = "white"))

mainland 
print(bornholm, vp = viewport(x = 0.82, y = 0.5, width = 0.3, height = 0.2))
  • What do you mean "keep the actual size of the small island"? Which small island - there seems to be a few? Why isn't it the right size? Does that code produce that plot? – Spacedman Aug 26 at 16:11
  • @Spacedman: I mean the island on the right with the text "Bornholms Hospital". In reality this island is bigger... The plot is for one of the regions in Denmark which includes the "island" (you are right there are many "islands"). – David Aug 27 at 9:53
  • 1
    Its not clear from your question that the island is an "inset map" on the plot and not actually in that location - that's what confused me! – Spacedman Aug 27 at 11:21
  • @Spacedman: I have used viewport()... Is that what you mean by insert map? – David Aug 27 at 12:08
  • 1
    @Spacedman: Yes, like USA but with Alaska in its real size and not just so fit Alaska on the screen. The location does not matter the relative size matters. e.g. Alaska is larger than Texas but you can't see that on this map: cpt.dk/artikel/usa-kort-med-stater – David Aug 27 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.