0

I've been trying to plot a shapefile using sf package plot function but I get this:

(The shapefile can be found here: https://drive.google.com/open?id=1AKMP9i549xESStN-R59UUU80OmkXy1XM)

sf <- st_read('fisiografia_cortado_disolve_gapis_des.shp')
plot(sf, lty = 0)

I can't display the key correctly. I've been playing with par function but I think I'm doing all wrong because nothing changes.

I tried:

par(mar = c(10,10,10,20)) 

and many other combinations (c(10,5,5,20), c(10,10,10,10)) but I think sf plots doesn't rely on par settings (forgive if I'm wrong).

I also tried to use the key.size attribute within the plot function but it only changes the width of the key (see the left image below) and if it is too big only the key is shown (right).

plot(sf, lty = 0, key.size = 1)
plot(sf, lty = 0, key.size = 10)

I'd like to show correctly the key and, if possible, change its size.

Anyone has gone through the same problem?

noriega
  • 447
  • 1
  • 9
  • 23

1 Answers1

2

You can adjust the oma parameter of par to show the full label.

library(sf)

dt <- st_read(system.file("shape/nc.shp", package="sf"))

par(oma = c(0, 0, 0, 4))
plot(dt["NAME"])

enter image description here

You can also use key.size as long as you give it a unit with lcm(). See https://r-spatial.github.io/sf/articles/sf5.html#color-keys

par(oma = c(0, 0, 0, 0)) # just resetting par
plot(dt["NAME"], key.size = lcm(4))

enter image description here

jsta
  • 3,216
  • 25
  • 35