library(tidyverse)
library(plotly)
library(gridExtra)
library(sf)
library(maps)
library(knitr)
GTcountry <- readr::read_csv("Country.csv")
climate_data <- readxl::read_excel("Climate.xlsx") %>% 
  mutate(dt = as.Date(dt, format = "%Y-%m-%d"),
         year = as.numeric(format(dt, "%Y")))

Введение

Анализ повышения среднегодовой температуры суши и океана имеет важное значение для понимания изменений климата на Земле. С учетом растущей загрязненности окружающей среды и изменений погодных условий, измерение и сравнение температурных тенденций может помочь оценить влияние глобального потепления на нашу планету. В данном исследовании рассмотрены данные о среднегодовой температуре суши и океана с 1900 года по настоящее время, а также данные о среднегодовой температуре в различных странах.

Среднегодовой прирост по суше и океану

Сравнение темпов изменения температуры суши и океана позволяет выявить различия в динамике изменения температурных показателей на суше и в водоемах.

temp_growth <- climate_data %>%
  group_by(year) %>%
  summarise(avg_temp = mean(LandAverageTemperature))

temp_growth$temperature_growth <- c(0, diff(temp_growth$avg_temp))
temp_ <- climate_data %>%
  group_by(year) %>%
  summarise(avg_temp = mean(LandAndOceanAverageTemperature))

temp_$temperature_growth <- c(0, diff(temp_$avg_temp))

d.temp <- tibble(
  place = "Ocean",
  year = 1901:2015, 
  d.temp = temp_$avg_temp[2:length(temp_$avg_temp)] - temp_$avg_temp[1:(length(temp_$avg_temp) - 1)])

d.temp <- tibble(
  place = "Land", 
  year = 1901:2015, 
  d.temp = temp_growth$avg_temp[2:length(temp_growth$avg_temp)] - temp_growth$avg_temp[1:(length(temp_growth$avg_temp) - 1)]) %>%
  rbind(d.temp)
p1 <- ggplot(d.temp, aes(year, d.temp, color = place)) + 
  geom_line() + 
  geom_point() + 
  geom_smooth(method = "lm", formula = "y~x") +
  facet_wrap(~place)

print(p1)

Прогноз изменения температуры суши океана

linear_model <- lm(d.temp ~ year, data = d.temp)

new_years <- 2016:2115  
new_data <- data.frame(year = new_years)

forecast_values1 <- predict(linear_model, newdata = new_data)

forecast_df <- data.frame(year = new_years, temperature = forecast_values1)

p2 <- ggplot() +
    geom_line(data = d.temp, aes(x = year, y = d.temp), color = "blue")+
    geom_line(data = forecast_df, aes(x = year, y = temperature), color ="red") +
    labs(x = "Year", y = "Temperature",
         title = "Прогноз изменения температуры") +
    scale_color_manual(name = "Data Type",
                       values = c("blue", "red"),
                       labels = c("Existing Data", "Forecast")) +
    facet_wrap(~place) +
    theme_minimal()
print(p2)

Сравнение темпов изменения климата в различных странах

country <- na.omit(GTcountry)
country_trends <- country %>%
  group_by(Country) %>%
  summarize(coefficient = coef(lm(AverageTemperature ~ dt))[2])

country_trends4 <- country_trends %>%
  top_n(4)

ТОП-4 СТРАНЫ ПО ПРИРОСТУ ТЕМПЕРАТУРЫ

kable(country_trends4)
Country coefficient
French Southern And Antarctic Lands 4.10e-05
Heard Island And Mcdonald Islands 3.71e-05
Turkmenistan 3.01e-05
Uzbekistan 3.06e-05
f <- country %>%
  filter(Country %in% c("French Southern And Antarctic Lands","Heard Island And Mcdonald Islands","Turkmenistan","Uzbekistan"),
         dt > as.Date("1900-01-01"))

model_ <- lm(AverageTemperature ~ dt + Country, data = f)

p4 <- ggplot(f, aes(x = dt, y = AverageTemperature, color = Country)) +
  labs(x = "Дата", y = "Температура суши",
       title = "Изменение климата в различных странах") +
  geom_smooth(method = "lm", se = FALSE) +
  theme(legend.position = "none") +
  theme_minimal() 

print(p4)

КАРТА СО СРАВНЕНИЕМ ПРИРОСТА ТЕМПЕРАТУРЫ

p3 <- map("world", fill = TRUE, plot = FALSE) %>%
  st_as_sf() %>%
  rename(Country = ID, geometry = geom) %>%
  left_join(country_trends, by = "Country") %>%
  ggplot(aes(geometry = geometry, fill = coefficient)) +
  geom_sf() +
  scale_fill_gradient(low = "blue", high = "red", name = "Value")
plotly::ggplotly(p3)