Skip to content

Instantly share code, notes, and snippets.

@igproj-fusion
Last active April 27, 2024 11:15
Show Gist options
  • Save igproj-fusion/b803ea6ff208268b5abee33013e39a5b to your computer and use it in GitHub Desktop.
Save igproj-fusion/b803ea6ff208268b5abee33013e39a5b to your computer and use it in GitHub Desktop.
pacman::p_load(
ncdf4,
sf,
rnaturalearth,
tidyverse,
reshape2,
scales)
world_map <- ne_countries(scale = "large",
returnclass = "sf")
box = c(xmin = 125, ymin = 25, xmax = 150, ymax = 50)
sf_use_s2(FALSE)
Asia <- st_crop(world_map, box)
FILE <- "C:/Users/ ... /******.nc"
nc4data <- nc_open(FILE)
sst <- as.vector(ncvar_get(nc4data, "sst"))
melt(matrix(sst, ncol = 1440, byrow =T)) |>
filter(value != is.na(value)) |>
mutate(lon = Var2 / 4 - 0.125) |>
mutate(lat = Var1 / 4 - 90.125) |>
dplyr::select(lon, lat, sst = value) |>
filter(lon >= 90) |>
filter(lon <= 180) |>
filter(lat >= 0) |>
ggplot() +
geom_point(aes(x = lon, y = lat, color = sst), size = 2) +
geom_sf(data = Asia, linewidth = 0.1, color = "gray60") +
scale_color_gradient2(low = muted("blue"), mid = "white",
high = "red", midpoint = 15) +
theme_void() +
xlim(c(125, 150)) + ylim(c(25, 50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment