2 years ago

#65617

test-img

Freya Slootmans

tm_compass does not appear inside of graph

I'm trying to make a map of Europe using tmap and the eurostat package.

I want to add a compass and a scale bar to the map. However they don't appear inside the graph, but outside of the map, at the bottom. Does anyone know what I'm doing wrong? I want the compass at the left top of the map, and the scale bar at the right bottom.

countries = gisco_get_countries(
    year = "2016",
    epsg = "3035",
    resolution = "3"
  )

br = c(0,40,50,65,80,150)

tm_shape(countries, bbox = c(23, 14, 74, 55) * 10e4) +
  tm_fill("#E0E0E0") +
  tm_shape(nuts2.sf) +
  tm_fill(
    "fatal_inj_30day",
    breaks = br,
    style = "fixed",
    palette = "Blues",
    alpha = .7,
    title = "Fatalities per million inhabitants \n(2018-2019)"
  ) +
  tm_compass(position = c("left","top")) +
  tm_scale_bar(position = c("right","bottom")) +
  tm_shape(countries) +
  tm_borders(lwd = .25) +
  tm_layout(
    bg.color = "#F2F2F2",
    outer.bg.color = "white",
    legend.bg.color = "white",
    legend.frame = "black",
    legend.title.size = 0.8,
    inner.margins = c(0, 0, 0, 0),
    outer.margins = c(0, 0, 0, 0),
    frame = TRUE,
    frame.lwd = 0,
    attr.outside = TRUE,
    legend.position = c("right", "top"),
    main.title = "Note: regions with 10 fatalities or less are not included in the Figure", 
    main.title.position = "left",
    main.title.size = 0.7
  )

enter image description here

tmap

0 Answers

Your Answer

Accepted video resources