I have a GIS vector file containing multiple attribute columns, such as t1, t2, t3, up to t8. My objective is to create individual plots for each attribute column within a panel display. Despite my attempts using terra, ggplot, and tidyterra, I consistently encounter errors during the process. I am not able to loop over with column names. aes fill
is not taking column names and considering it as a discrete variable. Any assistance in resolving this challenge would be greatly appreciated.
grids = vect('5k_grid_scenarios.gpkg')
grids = grids %>%
select(t1:t8)
p = c()
for (i in names(grids)){
plot =
grids %>%
autoplot(aes(fill = i))+
scale_fill_whitebox_c(palette = "pi_y_g")
p[[i]] =plot
}
ggarrange(p)
You may need to create a "long" version with
tidyr::pivot_longer()
and skip the use ofggarrange
.tidyterra does not provide a direct
pivot_longer()
method for Spatvector but you can convert the SpatVector to a tibble with a column with the geometry dat and regenerate the object after pivoting, see:Created on 2024-02-19 with reprex v2.1.0