EastBeast
EastBeast

Reputation: 209

Why is the legend distorted on my map using tmap?

I'm following an example from Geocomputation with R in Chapter 4, section 4.2.6. In the example from the book, the map of New Zealand that has the average elevation in the polygons/regions has a nice, compact legend that is easy to read and placed automatically in the upper left corner. See the image output from the book below.

Here is the link to the section of the book: https://geocompr.robinlovelace.net/spatial-operations.html

When I execute the same code to try to duplicate this map, the image that is produced for me has a very distorted legend with text that is also small. I've tried adjusting my Plots pane, exporting the image in multiple formats, etc., and the legend is still distorted like this.

enter image description here

The code below is what I am executing:

library(sf)
library(spData)
library(tmap)

# Summarize nz regions by average elevation
nz_agg = aggregate(x = nz_height, by = nz, FUN = mean)

# Map nz regions colored by average elevation
tm_shape(nz) +
  tm_polygons() +
  tm_shape(nz_agg) +
  tm_polygons(col = "elevation")

A couple months ago, when I produced tmaps with legends, I wasn't having this issue. I don't know if some setting has been changed or updated that I don't know about. The version of R that I'm using is 4.1.2 (2021-11-01) -- "Bird Hippie".

Upvotes: 1

Views: 214

Answers (1)

EastBeast
EastBeast

Reputation: 209

So, it wasn't a problem with my R version or the versions of the R packages I am using.

I use a laptop and have a couple of different locations where I use it for work. One location has multiple monitors; the other does not. I didn't notice it until researching this further, but when I plug in/unplug my monitors, sometimes it changes the resolution settings on my computer. Apparently, it wasn't enough for me to notice on my laptop until attempting to run this code. So, the cause of the distortion was due to changes on my computer that I was unaware of that happened automatically. I'll have to keep an eye on this.

Upvotes: 1

Related Questions