#For the story of this week I used three data : global temperature data, Hurricanes data, and storms data that I collect from my google search.

# data and libraries:

library(rvest)
## Warning: package 'rvest' was built under R version 4.3.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(kableExtra) 
## Warning: package 'kableExtra' was built under R version 4.3.2
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'tidyr' was built under R version 4.3.2
## Warning: package 'readr' was built under R version 4.3.2
## Warning: package 'purrr' was built under R version 4.3.2
## Warning: package 'stringr' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.4.4     ✔ stringr   1.5.1
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()          masks stats::filter()
## ✖ kableExtra::group_rows() masks dplyr::group_rows()
## ✖ readr::guess_encoding()  masks rvest::guess_encoding()
## ✖ dplyr::lag()             masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(readr)
library(ggplot2)

data= read.csv("C:/Users/Chafiaa/Downloads/data.csv")
data
##    Year Anomaly
## 1  1999    0.62
## 2  2000    0.40
## 3  2001    0.42
## 4  2002    0.57
## 5  2003    0.62
## 6  2004    0.62
## 7  2005    0.57
## 8  2006    0.68
## 9  2007    0.68
## 10 2008    0.59
## 11 2009    0.58
## 12 2010    0.68
## 13 2011    0.72
## 14 2012    0.61
## 15 2013    0.67
## 16 2014    0.68
## 17 2015    0.76
## 18 2016    0.94
## 19 2017    1.02
## 20 2018    0.92
## 21 2019    0.87
## 22 2020    1.00
## 23 2021    0.99
## 24 2022    0.87
## 25 2023    0.89
## 26 2024    1.22
ggplot(data, aes(x = Year, y = Anomaly, color = "Annual Mean")) +
  geom_line(linetype = "solid", linewidth = 0.5) + 
  geom_point(color = "red", shape = 21) + 
  geom_smooth(method = "lm", formula = y ~ x, se = FALSE, aes(color = "Linear Regression"), linetype = "solid", linewidth = 0.5) + 
  scale_x_continuous(breaks = seq(1880, 2023, 20), expand = c(0,0)) +
  scale_y_continuous(limits = c(-0.5, 1.5), expand = c(0,0)) +
  scale_color_manual(name = "Legend", values = c("Annual Mean" = "blue", "Linear Regression" = "green"),
                     labels = c("Annual Mean", "Linear Regression")) +
  theme_light() +
  labs(x = "Year", y = "Temperature Anomaly",
       title = "GLOBAL LAND AND OCEAN TEMPERATURE",
       subtitle = "YEARLY TEMPERATURE ANOMALIES 1997 to 2022") +
  theme(legend.position = c(0.2, 0.85),
        plot.title = element_text(color = "purple", face = "bold")) 

# from the plot of global temperature we can see that the ocean and the land is getting warmer over the years, but during covid pandemic lock down we can see the temperature is lower ~2021.
data1= read.csv("C:/Users/Chafiaa/Downloads/Tornado statistics.csv")
data1
##    Date Tornadoes Fatalities
## 1  1995      1162         37
## 2  1996      1205         26
## 3  1997      1149         72
## 4  1998      1448        128
## 5  1999      1421         94
## 6  2000       972         31
## 7  2001      1101         32
## 8  2002       934         28
## 9  2003      1555         97
## 10 2004      1640         29
## 11 2005      1322         17
## 12 2006      1140         83
## 13 2007      1148         87
## 14 2008      1722        130
## 15 2009      1122         22
## 16 2010      1195         37
## 17 2011      1802        557
## 18 2012       923         75
## 19 2013       844         45
## 20 2014       929         51
## 21 2015      1071         16
## 22 2016      1109         38
## 23 2017      1389         41
## 24 2018       983          6
## 25 2019      1651         42
## 26 2020      1150         80
## 27 2021       984         13
## 28 2022      1387        106
## 29 2023      1393         NA
library(ggplot2)


ggplot(data=data1, aes(x=Date, y=Tornadoes, group=1)) +
  geom_line(color="red")+
  geom_point()

# from Tornadoes plot we can see the tornadoes are fluctuate but I see few during the global lock down on 2021 
data2= read.csv("C:/Users/Chafiaa/Downloads/Global Historical Tropical Cyclone Statistics.csv")
data2
##    Year Named.Storms Named.Storm.Days Hurricanes Hurricanes.Days
## 1  1980           73           367.25         43          143.75
## 2  1981           82           363.75         45          125.75
## 3  1982           81           428.75         46          162.25
## 4  1983           79           369.50         42          150.00
## 5  1984           93           439.00         47          160.25
## 6  1985           95           455.25         51          163.50
## 7  1986           88           407.75         48          172.25
## 8  1987           83           400.75         39          133.75
## 9  1988           74           336.25         39          146.00
## 10 1989           91           440.00         55          199.25
## 11 1990           92           499.25         58          218.75
## 12 1991           79           433.00         47          188.25
## 13 1992          101           559.75         59          253.75
## 14 1993           79           394.25         49          164.00
## 15 1994           93           514.75         51          213.25
## 16 1995           80           408.75         49          179.25
## 17 1996          100           505.50         57          218.25
## 18 1997           97           535.25         58          220.25
## 19 1998           89           418.50         50          179.25
## 20 1999           74           317.50         39          135.50
## 21 2000           90           392.50         45          160.50
## 22 2001           88           373.50         51          162.75
## 23 2002           82           384.50         41          171.50
## 24 2003           85           418.00         50          175.00
## 25 2004           86           442.00         51          216.00
## 26 2005           96           428.75         51          189.50
## 27 2006           81           369.50         42          165.75
## 28 2007           80           303.50         44          118.75
## 29 2008           90           376.75         40          132.50
## 30 2009           85           324.75         38          115.25
## 31 2010           68           289.75         39          112.00
## 32 2011           75           335.50         39          121.00
## 33 2012           88           424.75         47          154.00
## 34 2013           90           353.25         46          127.75
## 35 2014           77           368.75         46          150.75
## 36 2015           95           500.50         54          221.00
## 37 2016           83           413.50         47          163.25
## 38 2017           84           354.75         43          135.75
## 39 2018          103           540.75         59          223.50
## 40 2019           98           449.00         55          172.25
## 41 2020          104           380.25         46          115.25
## 42 2021           94           354.75         37          119.00
## 43 2022           87           335.75         40          115.25
##    Cat..3..Hurricanes Cat..3..Hurricanes.Days Accumulated.Cyclone.Energy
## 1                  19                   30.25                      638.0
## 2                  15                   19.50                      554.7
## 3                  21                   37.75                      709.2
## 4                  21                   47.25                      680.0
## 5                  20                   41.25                      726.2
## 6                  24                   27.75                      717.8
## 7                  16                   31.00                      695.0
## 8                  18                   39.75                      649.1
## 9                  19                   41.25                      625.4
## 10                 25                   56.75                      853.9
## 11                 21                   60.75                      930.8
## 12                 25                   65.75                      860.6
## 13                 32                   89.00                     1163.1
## 14                 24                   43.75                      710.4
## 15                 31                   80.50                     1019.0
## 16                 24                   54.25                      779.3
## 17                 27                   68.00                      960.0
## 18                 28                   87.75                     1099.2
## 19                 21                   46.00                      773.1
## 20                 21                   46.50                      606.4
## 21                 20                   39.25                      677.3
## 22                 24                   38.50                      672.4
## 23                 27                   69.50                      812.0
## 24                 25                   68.00                      833.0
## 25                 32                   99.00                     1024.4
## 26                 27                   79.50                      899.6
## 27                 27                   59.25                      761.0
## 28                 22                   41.75                      568.1
## 29                 24                   33.25                      613.9
## 30                 21                   49.00                      609.6
## 31                 19                   38.75                      526.8
## 32                 21                   36.50                      573.8
## 33                 24                   47.50                      740.5
## 34                 22                   37.00                      618.5
## 35                 26                   54.50                      724.0
## 36                 39                   88.00                     1047.0
## 37                 26                   58.75                      806.5
## 38                 20                   34.25                      621.1
## 39                 33                   91.00                     1108.4
## 40                 35                   64.50                      854.8
## 41                 24                   35.50                      599.1
## 42                 16                   49.00                      621.1
## 43                 17                   36.25                      559.6
data2<- data2 %>%
  pivot_longer(cols = c("Named.Storms", "Hurricanes", "Cat..3..Hurricanes"),
               names_to = "Category", values_to = "Count")

# Define the order of the facets
category_order <- c("Named.Storms", "Hurricanes", "Cat..3..Hurricanes")

# Reorder the levels of the "Category" factor
data2$Category <- factor(data2$Category, levels = category_order)

# Plot the data using facets and add connecting lines
p <- ggplot(data2, aes(x = Year, y = Count, color = Category, group = Category)) +
  geom_point() +
  geom_line() +
  facet_wrap(~Category, scales = "free_y", nrow = 3) +
  labs(x = "Year", y = "Count") +
  theme_minimal() +
  theme(legend.position = "bottom") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

p <- p + labs(
  title = "Meteorological Statistics",
  subtitle = "Yearly counts of meteorological events"
)

p <- p + scale_color_manual(values = c("NAMED STORMS" = "red", "HURRICAINES" = "green", "CAT 3 HURRICAINES" = "purple"))

p

# For Hurricanes we can see from the plot below it high on the 90s and from 2010 to 2020 and low during covid lock down  

conclusion: from looking at the plots I created today we can see that the temperatures of oceans and land is getting warmer over the years wich cause storms , Hurricanes and tornadoes, but durring the pandamic lock down our earth got some rest and we saw a low temperates and storms.