ExpandBB() function

Viewed 25

Hello I am having problems with this function - I'm working through Robin Lovelace's book Chapter 2 Geographic data in R | Geocomputation with R (robinlovelace.net)

I've attached all the packages mentioned in the chapter: library(sf) library(terra) library(spData) library(spDataLarge)

and in section 2.2.3, the book gives this code:

india = world[world$name_long == "India", ]
plot(st_geometry(india), expandBB = c(0, 0.2, 0.1, 1), col = "gray", lwd = 3)
plot(st_geometry(world_asia), add = TRUE)

which according to the book should giove a nice big picture of India. however when i run it I only get a tiny picture. I've tried altering the values in expandBB and managed to get a somewhat larger but still small pic with:

india = world[world$name_long == "India", ]
plot(st_geometry(india), expandBB = c(0, 3, 1.5, 15), col = "gray", lwd = 3)
plot(st_geometry(world_asia), add = TRUE)

but I can't find any obvious relationship between the input variables in expandBB and the size of the plot I get out, and I can't reproduce the example in the book by tweaking the numbers. I can't find any explanation of expandBB on the net - does anyone know how it works?

1 Answers

Expanding the bounding box will shrink the apparent map size, since you are including blank areas around the existing map. The size of the plot is limited by the plotting panel margins, so you could try reducing the plot margins via par:

par(mar = c(0, 0, 0, 0))
plot(st_geometry(india), col = 'grey')

enter image description here

Or plot with ggplot

library(ggplot2)

ggplot(india) + geom_sf(fill = '#d8e0a8') + theme_void()

enter image description here

Related