I have data in XYZ format (long, lat, elevation) that does not fit on a rectangular grid, but I would like to plot it as grid cells of different sizes.
To illustrate what I mean, the last two plots in this stars vignette illustrate exactly what I would like to do: https://r-spatial.github.io/stars/articles/stars4.html
In that vignette, they are able to plot the data as points, but then they are able to plot the data as cells of different sizes, which essentially fills in the gaps.
But I am having a hard time figuring out how to convert the data into a stars object and plot. An example of one of my files can be downloaded here: https://www.dropbox.com/s/u230o28109hhxee/elevation_8.0.dat?dl=1
Here is what I have so far:
library(stars)
library(sf)
f <- 'elevation_8.0.dat'
temp <- read.table(f)
colnames(temp) <- c('x','y','alt')
sfObj <- st_as_sf(temp, coords=1:2, crs=st_crs(4326))
plot(sfObj, cex=0.15)
dat <- st_as_stars(sfObj)
dat
> dat
stars object with 1 dimensions and 1 attribute
attribute(s):
alt
Min. :-4895.79
1st Qu.:-1813.55
Median : 1191.53
Mean : 48.76
3rd Qu.: 1829.30
Max. : 3702.25
dimension(s):
from to offset delta refsys point
geometry 1 43990 NA NA +proj=longlat +datum=WGS8... TRUE
values
geometry POINT (-128.867 42.1795),...,POINT (-102.176 28.3599)
plot(dat, as_points = TRUE)
Error in .image_scale(values, colors, breaks = breaks, key.pos = key.pos, :
object 'mar' not found