eliocamp / metR

Tools for Easier Analysis of Meteorological Fields
https://eliocamp.github.io/metR/
139 stars 22 forks source link

argumento clip en geom_contour_fill() no anda #182

Closed paocorrales closed 9 months ago

paocorrales commented 9 months ago

Este ejemplo no funciona. Es posible que sea un problema con los datos.

file1 <- "datos/wc2.1_10m_tmax_ACCESS-CM2_ssp585_2021-2040.tif"

download.file("https://geodata.ucdavis.edu/cmip6/10m/ACCESS-CM2/ssp585/wc2.1_10m_tmax_ACCESS-CM2_ssp585_2021-2040.tif", destfile = file1)

data <- data.table(rasterToPoints(tmp1))

mapa_asia <- rnaturalearth::ne_countries(continent = "Asia", returnclass = "sf",
                                         scale = 10)

data %>%
  ggplot(aes(x, y)) +
  geom_contour_fill(aes(z = diff, fill = after_stat(level), clip = mapa_asia))

Si hago un subset de los datos me aparece este Warning (y no see grafican los contornos):

Warning: Computation failed in stat_contour_fill(): not implemented for objects of class sfc_GEOMETRYCOLLECTION

Con los datos completes me devuelve esto:

Warning: Computation failed in stat_contour_fill(): polygons require at least 4 points

eliocamp commented 9 months ago

Reprex:

library(ggplot2)

file1 <- tempfile()

download.file("https://geodata.ucdavis.edu/cmip6/10m/ACCESS-CM2/ssp585/wc2.1_10m_tmax_ACCESS-CM2_ssp585_2021-2040.tif", destfile = file1)

data <- as.data.frame(terra::rast(file1), xy = TRUE)

mapa_asia <- rnaturalearth::ne_countries(continent = "Asia", returnclass = "sf",
                                         scale = 10)

ggplot(data, aes(x, y)) +
    metR::geom_contour_fill(aes(z = tmax01, fill = after_stat(level))) +
    geom_sf(data = mapa_asia, inherit.aes = FALSE, fill = NA, color = "black")


ggplot(data, aes(x, y)) +
    metR::geom_contour_fill(aes(z = tmax01, fill = after_stat(level)), clip = mapa_asia)
#> Warning: Computation failed in `stat_contour_fill()`:
#>  polygons require at least 4 points

Created on 2023-11-06 with reprex v2.0.2

eliocamp commented 9 months ago

Se cierra con: 2830c571676e564f462962b85819d28a63460385