to_raster | R Documentation |
Estimate the raster dimensions of a scattered 2D or 3D signal based on its pixel coordinates.
# Rasterize a 2D signal
to_raster(x, y, vals)
# Rasterize a 3D signal
to_raster3(x, y, z, vals)
# Check if coordinates are gridded
is_gridded(x, tol = sqrt(.Machine$double.eps))
x , y , z |
The coordinates of the data to be rasterized. For |
vals |
The data values to be rasterized. |
tol |
The tolerance allowed when estimating the resolution. Noise in the sampling rate will be allowed up to this amount when determining if the data is approximately gridded or not. |
This is meant to be a more efficient version of approx2()
when the data is already (approximately) gridded. Otherwise, approx2()
is used.
A numeric vector giving the estimated raster dimensions.
Kylie A. Bemis
approx2
# create an image
set.seed(1)
i <- seq(-4, 4, length.out=12)
j <- seq(1, 3, length.out=9)
co <- expand.grid(x=i, y=j)
z <- matrix(atan(co$x / co$y), nrow=12, ncol=9)
vals <- 10 * (z - min(z)) / diff(range(z))
# scatter coordinates and flatten image
d <- expand.grid(x=jitter(1:12), y=jitter(1:9))
d$vals <- as.vector(z)
# rasterize
to_raster(d$x, d$y, d$vals)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.