File:January Temperature Middle East 1.png
Original file (2,031 × 1,973 pixels, file size: 2.62 MB, MIME type: image/png)
Captions
Summary
[edit]DescriptionJanuary Temperature Middle East 1.png |
English: January Temperature of Middle East |
Date | |
Source | Own work |
Author | Merikanto |
This plotting is based on WorldClim 2.1
https://www.worldclim.org/data/worldclim21.html
Fick, S.E. and R.J. Hijmans, 2017. WorldClim 2: new 1km spatial resolution climate surfaces for global land areas. International Journal of Climatology 37 (12): 4302-4315.
"R" source code. mus copr output file
- Asenna tarvittavat paketit vain, jos install_packages_yes on TRUE
install_packages_yes <- FALSE
if (install_packages_yes) {
install.packages("terra")
install.packages("ggplot2")
install.packages("sf")
install.packages("rnaturalearth")
install.packages("rnaturalearthdata")
install.packages("rayshader")
install.packages("viridis")
install.packages("ggtext")
install.packages("metR")
}
- Lataa tarvittavat kirjastot
library(terra)
library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(viridis)
library(ggtext)
library(metR)
library(rayshader)
- Lataa ja prosessoi WorldClim-data
- Define the WorldClim data URL for the desired resolution (10 minutes)
url <- "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/wc2.1_10m_tavg.zip"
- Define the local file path
temp_file <- tempfile(fileext = ".zip")
- Download the file
download.file(url, temp_file, mode = "wb")
- Unzip the file
temp_dir <- tempdir()
unzip(temp_file, exdir = temp_dir)
- List the files in the unzipped directory
files <- list.files(temp_dir, pattern = "\\.tif$", full.names = TRUE)
- Load the raster files as a SpatRaster object
worldclim_raster <- rast(files)
- Define the extent for the Middle East region (approximate coordinates)
extent_me <- ext(30, 55, 25, 45)
- Lataa Lähi-idän rajaus
bbox <- ext(30, 55, 25, 45)
- Select January and July layers
jan_raster <- rast(file.path(temp_dir, "wc2.1_10m_tavg_01.tif"))
jul_raster <- rast(file.path(temp_dir, "wc2.1_10m_tavg_07.tif"))
- Crop the layers to the Middle East region
jan_me_raster <- crop(jan_raster, extent_me)
jul_me_raster <- crop(jul_raster, extent_me)
- Convert to data frames for ggplot2
jan_df <- as.data.frame(jan_me_raster, xy = TRUE)
jul_df <- as.data.frame(jul_me_raster, xy = TRUE)
- Varmista, että sarakkeen nimi on 'layer'
names(jan_df)[3] <- "layer"
names(jul_df)[3] <- "layer"
- Lataa DEM-data ja prosessoi se
dem_url <- "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/wc2.1_10m_elev.zip"
dem_temp_file <- tempfile(fileext = ".zip")
download.file(dem_url, dem_temp_file, mode = "wb")
unzip(dem_temp_file, exdir = temp_dir)
dem_raster <- rast(file.path(temp_dir, "wc2.1_10m_elev.tif"))
- Crop the DEM layer to the Middle East region
dem_me_raster <- crop(dem_raster, extent_me)
- Convert DEM to a data frame for ggplot2
dem_df <- as.data.frame(dem_me_raster, xy = TRUE)
- Varmista, että DEM-sarakkeen nimi on 'layer'
names(dem_df)[3] <- "layer"
- Lataa luonnonmaan tiedot
- Load natural earth data for countries, rivers, and lakes
- world <- ne_countries(scale = "medium", returnclass = "sf")
rivers <- ne_download(scale = "medium", type = "rivers_lake_centerlines", category = "physical", returnclass = "sf")
lakes <- ne_download(scale = "medium", type = "lakes", category = "physical", returnclass = "sf")
coastlines <- ne_download(scale = "medium", type = "coastline", category = "physical", returnclass = "sf")
rivers_vect <- vect(rivers)
middle_east_rivers <- crop(rivers_vect, bbox)
lakes_vect <- vect(lakes)
middle_east_lakes <- crop(lakes_vect, bbox)
coastlines_vect <- vect(coastlines)
middle_east_coastlines <- crop(coastlines_vect, bbox)
- ocean <- ne_download(scale = "medium", type = "ocean", category = "physical", returnclass = "sf")
- Define a base plot function with contours, transparency, and DEM overlay
base_plot <- function(data, title) {
ggplot() +
#geom_raster(data = dem_df, aes(x = x, y = y, fill = layer), alpha = 0.3) +
scale_fill_gradient(low = "white", high = "black", name = "Elevation", guide = "none") +
geom_raster(data = data, aes(x = x, y = y, fill = layer), alpha = 1.0, interpolate = TRUE) +
#geom_raster(data = dem_df, aes(x = x, y = y, fill = layer), alpha = 0.1) +
geom_contour(data = data, aes(x = x, y = y, z = layer), color = "#5f0000", linewidth=0.5, alpha=0.5, breaks = seq(-20, 50, by = 5)) +
- metR::geom_text_contour(aes(z = layer, label = after_stat(level))) +
geom_text_contour(data = data, aes(x = x, y = y, z = layer), breaks = seq(-50, 50, by = 5), check_overlap = TRUE) +
scale_fill_viridis(option = "turbo", name = "Temp (°C)") +
#geom_sf(data = middle_east_world, fill = NA, color = "black") +
#geom_sf(data = middle_east_rivers, color = "blue") +
#geom_sf(data = middle_east_lakes, fill = "blue", color = "blue") +
#geom_sf(data = middle_east_coastlines, fill = "blue", color = "blue") +
geom_sf(data = rivers, color = "blue", alpha=0.5) +
geom_sf(data = lakes, fill = "blue", color = "blue", alpha=0.5) +
geom_sf(data = coastlines, fill = "blue", color = "blue", alpha=0.5) +
#geom_sf(data = ocean, fill = "blue", color = "blue") +
coord_sf(xlim = c(30, 55), ylim = c(25, 45)) +
theme_minimal() +
labs(title = title, x = "Longitude", y = "Latitude")
}
- print("TEOUK")
- stop(-1)
- Plot January temperature
p1 <- base_plot(jan_df, "Average Temperature in January of Middle East ")
- Plot July temperature
p2 <- base_plot(jul_df, "Average Temperature in July of Middle East ")
- Print the plots
print(p1)
print(p2)
- Tallenna kuvat PNG-tiedostoina
ggsave("January_Temperature_Middle_East.png", plot = p1, width = 10, height = 8, bg="white", dpi = 300)
ggsave("July_Temperature_Middle_East.png", plot = p2, width = 10, height = 8, bg="white", dpi = 300)
Licensing
[edit]- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 08:39, 21 July 2024 | 2,031 × 1,973 (2.62 MB) | Merikanto (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.