简体   繁体   中英

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.

在此处输入图像描述

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".

So, it wasn't a problem with my version of R or the versions of the R packages I am using. This is ridiculous.....I use a laptop, and have a couple 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 is 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. Thanks for attempting to help, regardless!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM