Convert a concentration field result to a tidy data frame
Source:R/estimate_concentration_field.R
field_to_df.RdExpands the N x N field matrix into a long data.frame suitable for
plotting with ggplot2 or further analysis.
Arguments
- result
A list returned by
estimate_concentration_field().- inside_only
Logical. If
TRUE(default), only rows inside the mask (i.e. non-NAfield values) are returned.
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