eliocamp/metR

argumento clip en geom_contour_fill() no anda

paocorrales opened this issue · 2 comments

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

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

Se cierra con: 2830c57