From d46d5fd6977d7e482e40653466c24e1933c3b0df Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 28 Feb 2023 19:36:10 -0700 Subject: [PATCH] new file: readslice.R --- python/readslice.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 python/readslice.R diff --git a/python/readslice.R b/python/readslice.R new file mode 100644 index 0000000..b406ab5 --- /dev/null +++ b/python/readslice.R @@ -0,0 +1,23 @@ +# Load required packages +library(ggplot2) +library(raster) + +# Read in the NetCDF file +ds <- brick("smoke.nc") + +# Extract the latitude, longitude, and PM2.5 data +lat <- ds$lat +lon <- ds$lon +pm25 <- ds$pm25 + +# Convert the PM2.5 data to a raster object +pm25_raster <- raster(t(pm25)) +extent(pm25_raster) <- extent(lon[1], lon[length(lon)], lat[length(lat)], lat[1]) + +# Plot the raster object using ggplot2 +ggplot() + + geom_raster(data = as.data.frame(pm25_raster), aes(x = lon, y = lat, fill = value)) + + scale_fill_gradient(low = "white", high = "red") + + coord_fixed() + + theme_bw() + -- 2.11.4.GIT