I am trying to plot a heat map of gridded data on a curvilinear grid. From what I have read the stars
package provides this functionality using geom_stars
on a stars object created using st_as_stars
with a curvilinear
option. There is a nice blog post on it here. However, when I try to use this method it fails. Simple reprex below:
library(stars)
library(ggplot2)
lng <- rbind(c(-2.099361, -2.098536, -2.097710, -2.096885),
c(-2.099350, -2.098525, -2.097699, -2.096874), c(-2.099339, -2.098514,
-2.097688, -2.096863), c(-2.099328, -2.098503, -2.097677, -2.096852))
lat <- rbind(c(57.10963, 57.10963, 57.10962, 57.10962), c(57.11008,
57.11008, 57.11007, 57.11007),c(57.11053, 57.11053, 57.11052, 57.11051), c(57.11098, 57.11098, 57.11097, 57.11096))
arr <- rbind(1:4, 5:8, 9:12, 13:16)
arr_star <- st_as_stars(arr, curvilinear = list(west_east = lng,
south_north = lat))
ggplot() + geom_stars(data = arr_star, alpha = 0.75)
The error message is:
Error:
! Tibble columns must have compatible sizes.
• Size 2: Column `curvilinear`.
• Size 16: Columns `X1`, `X2`, and `X`.
ℹ Only values of size one are recycled.
Run `rlang::last_error()` to see where the error occurred.
Looking at the code for geom_stars
, it seems to be trying to use dplyr::as_tibble
on arr_star
and it makes sense that this would fail. Any idea where I'm going wrong?