Skip to contents

Expands the N x N field matrix into a long data.frame suitable for plotting with ggplot2 or further analysis.

Usage

field_to_df(result, inside_only = TRUE)

Arguments

result

A list returned by estimate_concentration_field().

inside_only

Logical. If TRUE (default), only rows inside the mask (i.e. non-NA field values) are returned.

Value

A data.frame with columns x, y, field, inside, and optionally source.

Examples

library(sf)
set.seed(1)
sq   <- st_polygon(list(cbind(c(0,10,10,0,0), c(0,0,10,10,0))))
mask <- st_sfc(sq)
tc   <- data.frame(x = runif(50, 1, 9), y = runif(50, 1, 9))
res  <- estimate_concentration_field(mask, tc, grid_resolution = 64L,
                                     verbose = FALSE)
df   <- field_to_df(res)
head(df)
#>             x         y      field inside source
#> 131 0.1140625 0.1140625 0.01007045   TRUE      0
#> 132 0.2796875 0.1140625 0.02016409   TRUE      0
#> 133 0.4453125 0.1140625 0.03030098   TRUE      0
#> 134 0.6109375 0.1140625 0.04049471   TRUE      0
#> 135 0.7765625 0.1140625 0.05074885   TRUE      0
#> 136 0.9421875 0.1140625 0.06105318   TRUE      0