0
votes

I am very new to spatial analysis in R, been learning as much as i can but hit a road block.

Objectives:

  1. To visualise a 15000 sites (across England) data set spatially - Done
  2. To measure the distance between the different variables in the data set [ Site A , Site B, Site C] - Done using st_distance
  3. To visualise the distance between the sites spatially - Lost?

My data is arranged as columns :

NGR_10_FIG | TYPE | CODE | Grid | X | Y | Lat | Long

Should I use a different method to visualise the distance? Am I trying to over complicate this and should I do it differently?

Thank you. Any comments are welcome.

1
I would lay a grid across England, and count the sites per grid cell. Doing site to site distances would imply 15000^2 distance pairs; that is a lot...Jindra Lacko
Yes, I think trying to visualise 15000^2 values spatially is overcomplicating things (and very difficult). Depending on your task, you could for example visualise these values on a histogram, which would show you what distances are most common between sites. If you're new to spatial data in R, check out this book geocompr.robinlovelace.nethugh-allan

1 Answers

0
votes

The following code can be used to visualise the distances between the first polygon in nc data (since I don't have the data you mentioned) and all the other polygons in nc.

# packages
suppressPackageStartupMessages({
  library(sf)
  library(tmap)
})

# data
nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)

# compute distances from first region
nc$dists <- st_distance(nc, nc[1, ])

# plot
tm_shape(nc) + 
  tm_polygons(col = "dists") + 
tm_shape(nc[1, ]) + 
  tm_polygons(col = "grey85", lwd = 1.75)

Created on 2021-10-27 by the reprex package (v2.0.1)

It's pretty simple, but it may be good enough. The same code also works for larger regions (provided that you are considering just one polygon at a time):

# packages
library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1

# data
bounding_box <- st_sfc(st_polygon(list(rbind(c(0, 0), c(1, 0), c(1, 1), c(0, 1), c(0, 0)))))
regions <- st_make_grid(bounding_box, n = c(100, 100))
length(regions)
#> [1] 10000

# compute distances from region 5250 (which is more or less in the middle)
dists <- st_distance(regions, regions[5250])

# plot
cols <- terrain.colors(15)[cut(dists, 15)]
par(mar = rep(0, 4))
plot(regions, col = cols)

Created on 2021-10-27 by the reprex package (v2.0.1)

I don't know how to visualise all the distances at the same time.