# Reference: https://www.ncei.noaa.gov/access/monitoring/climate-at-a-glance/global/time-series/globe/land_ocean/12/9/1998-2023?trend=true&trend_base=100&begtrendyear=1998&endtrendyear=2023

df1 = read.csv("https://raw.githubusercontent.com/enidroman/Data_608_Knowledge_and_Visual_Analytics/main/Global%20Land%20and%20Ocean%20Temp%202.csv")
df1
##    Global.Land.and.Ocean.October...September.Temperature.Anomalies       X
## 1                                           Units: Degrees Celsius        
## 2                                           Base Period: 1901-2000        
## 3                                                    Missing: -999        
## 4                                                             Year Anomaly
## 5                                                             1997    0.42
## 6                                                             1998    0.67
## 7                                                             1999    0.44
## 8                                                             2000    0.45
## 9                                                             2001    0.48
## 10                                                            2002    0.63
## 11                                                            2003     0.6
## 12                                                            2004    0.57
## 13                                                            2005    0.67
## 14                                                            2006    0.67
## 15                                                            2007    0.69
## 16                                                            2008    0.53
## 17                                                            2009    0.64
## 18                                                            2010    0.75
## 19                                                            2011    0.63
## 20                                                            2012    0.64
## 21                                                            2013    0.68
## 22                                                            2014    0.76
## 23                                                            2015    0.83
## 24                                                            2016    1.08
## 25                                                            2017    0.94
## 26                                                            2018    0.86
## 27                                                            2019    0.95
## 28                                                            2020    1.04
## 29                                                            2021    0.86
## 30                                                            2022    0.93
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## 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
df_row<- df1[-c(1, 2, 3, 4), ]
df_row
##    Global.Land.and.Ocean.October...September.Temperature.Anomalies    X
## 5                                                             1997 0.42
## 6                                                             1998 0.67
## 7                                                             1999 0.44
## 8                                                             2000 0.45
## 9                                                             2001 0.48
## 10                                                            2002 0.63
## 11                                                            2003  0.6
## 12                                                            2004 0.57
## 13                                                            2005 0.67
## 14                                                            2006 0.67
## 15                                                            2007 0.69
## 16                                                            2008 0.53
## 17                                                            2009 0.64
## 18                                                            2010 0.75
## 19                                                            2011 0.63
## 20                                                            2012 0.64
## 21                                                            2013 0.68
## 22                                                            2014 0.76
## 23                                                            2015 0.83
## 24                                                            2016 1.08
## 25                                                            2017 0.94
## 26                                                            2018 0.86
## 27                                                            2019 0.95
## 28                                                            2020 1.04
## 29                                                            2021 0.86
## 30                                                            2022 0.93
colnames(df_row) <- c("YEAR", "ANOMALY TEMP") # change column names of all the columns in the dataframe print(df)
df_row
##    YEAR ANOMALY TEMP
## 5  1997         0.42
## 6  1998         0.67
## 7  1999         0.44
## 8  2000         0.45
## 9  2001         0.48
## 10 2002         0.63
## 11 2003          0.6
## 12 2004         0.57
## 13 2005         0.67
## 14 2006         0.67
## 15 2007         0.69
## 16 2008         0.53
## 17 2009         0.64
## 18 2010         0.75
## 19 2011         0.63
## 20 2012         0.64
## 21 2013         0.68
## 22 2014         0.76
## 23 2015         0.83
## 24 2016         1.08
## 25 2017         0.94
## 26 2018         0.86
## 27 2019         0.95
## 28 2020         1.04
## 29 2021         0.86
## 30 2022         0.93
str(df_row)
## 'data.frame':    26 obs. of  2 variables:
##  $ YEAR        : chr  "1997" "1998" "1999" "2000" ...
##  $ ANOMALY TEMP: chr  "0.42" "0.67" "0.44" "0.45" ...
#install.packages('weathermetrics')
library('weathermetrics')
## Warning: package 'weathermetrics' was built under R version 4.2.3
# Convert "ANOMALY TEMP" column to numeric
df_row$`ANOMALY TEMP` <- as.numeric(df_row$`ANOMALY TEMP`)

# Check the data types again
str(df_row)
## 'data.frame':    26 obs. of  2 variables:
##  $ YEAR        : chr  "1997" "1998" "1999" "2000" ...
##  $ ANOMALY TEMP: num  0.42 0.67 0.44 0.45 0.48 0.63 0.6 0.57 0.67 0.67 ...
# Now you can apply the temperature conversion
df_f <- df_row
df_f$`ANOMALY TEMP` <- celsius.to.fahrenheit(df_f$`ANOMALY TEMP`)
df_f
##    YEAR ANOMALY TEMP
## 5  1997        32.76
## 6  1998        33.21
## 7  1999        32.79
## 8  2000        32.81
## 9  2001        32.86
## 10 2002        33.13
## 11 2003        33.08
## 12 2004        33.03
## 13 2005        33.21
## 14 2006        33.21
## 15 2007        33.24
## 16 2008        32.95
## 17 2009        33.15
## 18 2010        33.35
## 19 2011        33.13
## 20 2012        33.15
## 21 2013        33.22
## 22 2014        33.37
## 23 2015        33.49
## 24 2016        33.94
## 25 2017        33.69
## 26 2018        33.55
## 27 2019        33.71
## 28 2020        33.87
## 29 2021        33.55
## 30 2022        33.67
df_index <- df_f                        # Duplicate data
rownames(df_index) <- 1:nrow(df_index)    # Assign sequence to row names
df_index 
##    YEAR ANOMALY TEMP
## 1  1997        32.76
## 2  1998        33.21
## 3  1999        32.79
## 4  2000        32.81
## 5  2001        32.86
## 6  2002        33.13
## 7  2003        33.08
## 8  2004        33.03
## 9  2005        33.21
## 10 2006        33.21
## 11 2007        33.24
## 12 2008        32.95
## 13 2009        33.15
## 14 2010        33.35
## 15 2011        33.13
## 16 2012        33.15
## 17 2013        33.22
## 18 2014        33.37
## 19 2015        33.49
## 20 2016        33.94
## 21 2017        33.69
## 22 2018        33.55
## 23 2019        33.71
## 24 2020        33.87
## 25 2021        33.55
## 26 2022        33.67
df_rank <- df_index
df_rank$RANK <- rank(-df_rank$`ANOMALY TEMP`)
df_rank
##    YEAR ANOMALY TEMP RANK
## 1  1997        32.76 26.0
## 2  1998        33.21 14.0
## 3  1999        32.79 25.0
## 4  2000        32.81 24.0
## 5  2001        32.86 23.0
## 6  2002        33.13 18.5
## 7  2003        33.08 20.0
## 8  2004        33.03 21.0
## 9  2005        33.21 14.0
## 10 2006        33.21 14.0
## 11 2007        33.24 11.0
## 12 2008        32.95 22.0
## 13 2009        33.15 16.5
## 14 2010        33.35 10.0
## 15 2011        33.13 18.5
## 16 2012        33.15 16.5
## 17 2013        33.22 12.0
## 18 2014        33.37  9.0
## 19 2015        33.49  8.0
## 20 2016        33.94  1.0
## 21 2017        33.69  4.0
## 22 2018        33.55  6.5
## 23 2019        33.71  3.0
## 24 2020        33.87  2.0
## 25 2021        33.55  6.5
## 26 2022        33.67  5.0
library(DT)
## Warning: package 'DT' was built under R version 4.2.3
df_table <- datatable(df_rank)
df_table
df_rank$`ANOMALY TEMP` <- as.numeric(df_rank$`ANOMALY TEMP`)
str(df_rank)
## 'data.frame':    26 obs. of  3 variables:
##  $ YEAR        : chr  "1997" "1998" "1999" "2000" ...
##  $ ANOMALY TEMP: num  32.8 33.2 32.8 32.8 32.9 ...
##  $ RANK        : num  26 14 25 24 23 18.5 20 21 14 14 ...
library(plotly)
## Warning: package 'plotly' was built under R version 4.2.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.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
x <- df_rank$YEAR
y <- df_rank$`ANOMALY TEMP`
rank <- df_rank$'RANK'

# Create hover text with temperature, year, and rank
hover_text <- paste("ANOMALY TEMP: ", y, "°F<br>YEAR: ", x, "<br>RANK: ", rank)

fig <- plot_ly(data = df_rank, x = ~x, y = ~y, type = 'bar',
             text = hover_text,  # Include the hover text with all information
             hoverinfo = 'text',  # Specify hoverinfo to show the text
             marker = list(color = 'rgb(192, 57, 79)',
                           line = list(color = 'rgb(8, 48, 107)', width = 1.5)))

fig <- fig %>% layout(
  xaxis = list(title = "Year"),
  yaxis = list(title = "Number of Temperature °F", range = c(32, max(y))),
  bargap = 0.05,
  height = 500,  # Adjust the height as needed to make the graph taller
  width = 800  # Adjust the width to make the graph wider
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
# Add HTML-based annotations for title and subtitle
fig <- fig %>% add_annotations(
  text = "<b>GLOBAL LAND AND OCEAN TEMPERATURE</b>",
  x = 0, xref = "paper",
  y = 1.05, yref = "paper",
  showarrow = FALSE,
  font = list(size = 20),
  align = "left"
)

fig <- fig %>% add_annotations(
  text = "YEARLY TEMPERATURE ANOMALIES 1997 to 2022",
  x = 0, xref = "paper",
  y = 0.97, yref = "paper",
  showarrow = FALSE,
  font = list(size = 16),
  align = "left"
)

fig
x <- df_rank$YEAR
y <- df_rank$`ANOMALY TEMP`
rank <- df_rank$'RANK'

# Create hover text with year, temperature, and rank
hover_text <- paste("Year: ", x, "<br>ANOMALY TEMP: ", y, "<br>RANK: ", rank)

fig <- plot_ly(x = ~x, y = ~y, type = 'scatter', mode = 'lines', text = hover_text, textposition = 'top',
             hoverinfo = 'text',  # Specify hoverinfo to show the text
             line = list(color = 'rgb(192, 57, 79)'))

fig <- fig %>% layout(
  xaxis = list(title = "Year"),
  yaxis = list(title = "Temperature °F", range = c(32, max(y))),
  height = 500,  # Adjust the height as needed
  width = 800  # Adjust the width as needed
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
# Add HTML-based annotations for title and subtitle
fig <- fig %>% add_annotations(
  text = "<b>GLOBAL LAND AND OCEAN TEMPERATURE</b>",
  x = 0, xref = "paper",
  y = 1.05, yref = "paper",
  showarrow = FALSE,
  font = list(size = 20),
  align = "left"
)

fig <- fig %>% add_annotations(
  text = "YEARLY TEMPERATURE ANOMALIES 1997 to 2022",
  x = 0, xref = "paper",
  y = 0.97, yref = "paper",
  showarrow = FALSE,
  font = list(size = 16),
  align = "left"
)

fig
# reference: https://www.ncei.noaa.gov/access/monitoring/tornadoes/12/9?fatalities=false

df2 = read.csv("https://raw.githubusercontent.com/enidroman/Data_608_Knowledge_and_Visual_Analytics/main/Tornado%20statistics%20for%20the%20Contiguous%20U.S..csv")
df2
##    October.September.U.S..Tornadoes...denotes.preliminary.data.         X
## 1                                                          Date Tornadoes
## 2                                                        195109       246
## 3                                                        195209       255
## 4                                                        195309       392
## 5                                                        195409       556
## 6                                                        195509       578
## 7                                                        195609       505
## 8                                                        195709       787
## 9                                                        195809       624
## 10                                                       195909       621
## 11                                                       196009       608
## 12                                                       196109       676
## 13                                                       196209       704
## 14                                                       196309       452
## 15                                                       196409       677
## 16                                                       196509       900
## 17                                                       196609       582
## 18                                                       196709       882
## 19                                                       196809       676
## 20                                                       196909       644
## 21                                                       197009       633
## 22                                                       197109       854
## 23                                                       197209       789
## 24                                                       197309      1008
## 25                                                       197409      1040
## 26                                                       197509       912
## 27                                                       197609       897
## 28                                                       197709       794
## 29                                                       197809       815
## 30                                                       197909       835
## 31                                                       198009       889
## 32                                                       198109       789
## 33                                                       198209       964
## 34                                                       198309       935
## 35                                                       198409       949
## 36                                                       198509       730
## 37                                                       198609       757
## 38                                                       198709       634
## 39                                                       198809       612
## 40                                                       198909       928
## 41                                                       199009      1143
## 42                                                       199109      1177
## 43                                                       199209      1143
## 44                                                       199309      1297
## 45                                                       199409      1068
## 46                                                       199509      1162
## 47                                                       199609      1205
## 48                                                       199709      1149
## 49                                                       199809      1448
## 50                                                       199909      1421
## 51                                                       200009       972
## 52                                                       200109      1101
## 53                                                       200209       934
## 54                                                       200309      1555
## 55                                                       200409      1640
## 56                                                       200509      1322
## 57                                                       200609      1140
## 58                                                       200709      1148
## 59                                                       200809      1722
## 60                                                       200909      1122
## 61                                                       201009      1195
## 62                                                       201109      1802
## 63                                                       201209       923
## 64                                                       201309       844
## 65                                                       201409       929
## 66                                                       201509      1071
## 67                                                       201609      1109
## 68                                                       201709      1389
## 69                                                       201809       983
## 70                                                       201909      1651
## 71                                                       202009      1150
## 72                                                       202109       984
## 73                                                       202209      1387
## 74                                                       202309     1393*
##           X.1
## 1  Fatalities
## 2          35
## 3         233
## 4         470
## 5          81
## 6         131
## 7          85
## 8         147
## 9         109
## 10         62
## 11         45
## 12         52
## 13         31
## 14         31
## 15         49
## 16        319
## 17         98
## 18        106
## 19        141
## 20         69
## 21         68
## 22        163
## 23         34
## 24         76
## 25        376
## 26         64
## 27         45
## 28         40
## 29         51
## 30         82
## 31         34
## 32         25
## 33         57
## 34         36
## 35        122
## 36         96
## 37         18
## 38         42
## 39         34
## 40         30
## 41         84
## 42         41
## 43         11
## 44        135
## 45         45
## 46         37
## 47         26
## 48         72
## 49        128
## 50         94
## 51         31
## 52         32
## 53         28
## 54         97
## 55         29
## 56         17
## 57         83
## 58         87
## 59        130
## 60         22
## 61         37
## 62        557
## 63         75
## 64         45
## 65         51
## 66         16
## 67         38
## 68         41
## 69          6
## 70         42
## 71         80
## 72         13
## 73        106
## 74
df2_row<- df2[-c(1:47, 74), ]
df2_row
##    October.September.U.S..Tornadoes...denotes.preliminary.data.    X X.1
## 48                                                       199709 1149  72
## 49                                                       199809 1448 128
## 50                                                       199909 1421  94
## 51                                                       200009  972  31
## 52                                                       200109 1101  32
## 53                                                       200209  934  28
## 54                                                       200309 1555  97
## 55                                                       200409 1640  29
## 56                                                       200509 1322  17
## 57                                                       200609 1140  83
## 58                                                       200709 1148  87
## 59                                                       200809 1722 130
## 60                                                       200909 1122  22
## 61                                                       201009 1195  37
## 62                                                       201109 1802 557
## 63                                                       201209  923  75
## 64                                                       201309  844  45
## 65                                                       201409  929  51
## 66                                                       201509 1071  16
## 67                                                       201609 1109  38
## 68                                                       201709 1389  41
## 69                                                       201809  983   6
## 70                                                       201909 1651  42
## 71                                                       202009 1150  80
## 72                                                       202109  984  13
## 73                                                       202209 1387 106
colnames(df2_row) <- c("DATE", "TORNADOES", "FATALITIES") # change column names of all the columns in the dataframe print(df)
df2_row
##      DATE TORNADOES FATALITIES
## 48 199709      1149         72
## 49 199809      1448        128
## 50 199909      1421         94
## 51 200009       972         31
## 52 200109      1101         32
## 53 200209       934         28
## 54 200309      1555         97
## 55 200409      1640         29
## 56 200509      1322         17
## 57 200609      1140         83
## 58 200709      1148         87
## 59 200809      1722        130
## 60 200909      1122         22
## 61 201009      1195         37
## 62 201109      1802        557
## 63 201209       923         75
## 64 201309       844         45
## 65 201409       929         51
## 66 201509      1071         16
## 67 201609      1109         38
## 68 201709      1389         41
## 69 201809       983          6
## 70 201909      1651         42
## 71 202009      1150         80
## 72 202109       984         13
## 73 202209      1387        106
df2_index <- df2_row                         # Duplicate data
rownames(df2_index) <- 1:nrow(df2_index)    # Assign sequence to row names
df2_index 
##      DATE TORNADOES FATALITIES
## 1  199709      1149         72
## 2  199809      1448        128
## 3  199909      1421         94
## 4  200009       972         31
## 5  200109      1101         32
## 6  200209       934         28
## 7  200309      1555         97
## 8  200409      1640         29
## 9  200509      1322         17
## 10 200609      1140         83
## 11 200709      1148         87
## 12 200809      1722        130
## 13 200909      1122         22
## 14 201009      1195         37
## 15 201109      1802        557
## 16 201209       923         75
## 17 201309       844         45
## 18 201409       929         51
## 19 201509      1071         16
## 20 201609      1109         38
## 21 201709      1389         41
## 22 201809       983          6
## 23 201909      1651         42
## 24 202009      1150         80
## 25 202109       984         13
## 26 202209      1387        106
# Extract only the year (first four characters) from the YEAR column
df2_index$Year <- substr(df2_index$DATE, 1, 4)

df2_index$DATE <- NULL

# Print the resulting data frame with the Year column
df2_index
##    TORNADOES FATALITIES Year
## 1       1149         72 1997
## 2       1448        128 1998
## 3       1421         94 1999
## 4        972         31 2000
## 5       1101         32 2001
## 6        934         28 2002
## 7       1555         97 2003
## 8       1640         29 2004
## 9       1322         17 2005
## 10      1140         83 2006
## 11      1148         87 2007
## 12      1722        130 2008
## 13      1122         22 2009
## 14      1195         37 2010
## 15      1802        557 2011
## 16       923         75 2012
## 17       844         45 2013
## 18       929         51 2014
## 19      1071         16 2015
## 20      1109         38 2016
## 21      1389         41 2017
## 22       983          6 2018
## 23      1651         42 2019
## 24      1150         80 2020
## 25       984         13 2021
## 26      1387        106 2022
# Move the "LastColumn" to the first position
df2_col <- df2_index
df2_col <- df2_col[, c("Year", names(df2_col)[-which(names(df2_col) == "Year")])]

colnames(df2_col)[1] ="YEAR"

# Print the resulting data frame
df2_col
##    YEAR TORNADOES FATALITIES
## 1  1997      1149         72
## 2  1998      1448        128
## 3  1999      1421         94
## 4  2000       972         31
## 5  2001      1101         32
## 6  2002       934         28
## 7  2003      1555         97
## 8  2004      1640         29
## 9  2005      1322         17
## 10 2006      1140         83
## 11 2007      1148         87
## 12 2008      1722        130
## 13 2009      1122         22
## 14 2010      1195         37
## 15 2011      1802        557
## 16 2012       923         75
## 17 2013       844         45
## 18 2014       929         51
## 19 2015      1071         16
## 20 2016      1109         38
## 21 2017      1389         41
## 22 2018       983          6
## 23 2019      1651         42
## 24 2020      1150         80
## 25 2021       984         13
## 26 2022      1387        106
str(df2_col)
## 'data.frame':    26 obs. of  3 variables:
##  $ YEAR      : chr  "1997" "1998" "1999" "2000" ...
##  $ TORNADOES : chr  "1149" "1448" "1421" "972" ...
##  $ FATALITIES: chr  "72" "128" "94" "31" ...
df2_col$`TORNADOES` <- as.numeric(df2_col$`TORNADOES`)
df2_col$'FATALITIES' <- as.numeric(df2_col$'FATALITIES')
str(df2_col)
## 'data.frame':    26 obs. of  3 variables:
##  $ YEAR      : chr  "1997" "1998" "1999" "2000" ...
##  $ TORNADOES : num  1149 1448 1421 972 1101 ...
##  $ FATALITIES: num  72 128 94 31 32 28 97 29 17 83 ...
df2_rank <-df2_col
df2_rank$'TORNADOES RANK' <- rank(-df2_rank$`TORNADOES`)
df2_rank$'FATALITIES RANK' <- rank(-df2_rank$`FATALITIES`)
df2_rank <- df2_rank[, c(1:2, 4, 3, 5:ncol(df2_rank))]

df2_rank
##    YEAR TORNADOES TORNADOES RANK FATALITIES FATALITIES RANK
## 1  1997      1149             13         72              11
## 2  1998      1448              6        128               3
## 3  1999      1421              7         94               6
## 4  2000       972             22         31              19
## 5  2001      1101             18         32              18
## 6  2002       934             23         28              21
## 7  2003      1555              5         97               5
## 8  2004      1640              4         29              20
## 9  2005      1322             10         17              23
## 10 2006      1140             15         83               8
## 11 2007      1148             14         87               7
## 12 2008      1722              2        130               2
## 13 2009      1122             16         22              22
## 14 2010      1195             11         37              17
## 15 2011      1802              1        557               1
## 16 2012       923             25         75              10
## 17 2013       844             26         45              13
## 18 2014       929             24         51              12
## 19 2015      1071             19         16              24
## 20 2016      1109             17         38              16
## 21 2017      1389              8         41              15
## 22 2018       983             21          6              26
## 23 2019      1651              3         42              14
## 24 2020      1150             12         80               9
## 25 2021       984             20         13              25
## 26 2022      1387              9        106               4
df2_table <- datatable(df2_rank)
df2_table
library(plotly)
x <- df2_rank$YEAR
y <- df2_rank$`TORNADOES`
rank <- df2_rank$'TORNADOES RANK'

# Create hover text with temperature, year, and rank
hover_text <- paste("TORNADOES: ", y, "<br>YEAR: ", x, "<br>TORNADOES RANK: ", rank)

fig <- plot_ly(data = df2_rank, x = ~x, y = ~y, type = 'bar',
             text = hover_text,  # Include the hover text with all information
             hoverinfo = 'text',  # Specify hoverinfo to show the text
             marker = list(color = 'GREEN',
                           line = list(color = 'rgb(8, 48, 107)', width = 1.5)))

fig <- fig %>% layout(
  xaxis = list(title = "Year"),
  yaxis = list(title = "Number of Tornadoes", range = c(32, max(y))),
  bargap = 0.05,
  height = 500,  # Adjust the height as needed to make the graph taller
  width = 800  # Adjust the width to make the graph wider
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
# Add HTML-based annotations for title and subtitle
fig <- fig %>% add_annotations(
  text = "<b>U.S. TORNADOES</b>",
  x = 0, xref = "paper",
  y = 1.05, yref = "paper",
  showarrow = FALSE,
  font = list(size = 20),
  align = "left"
)

fig <- fig %>% add_annotations(
  text = "1997 TO 2022",
  x = 0, xref = "paper",
  y = 0.97, yref = "paper",
  showarrow = FALSE,
  font = list(size = 16),
  align = "left"
)

fig
x <- df2_rank$YEAR
y <- df2_rank$`TORNADOES`
rank <- df2_rank$'TORNADOES RANK'

# Create hover text with year, temperature, and rank
hover_text <- paste("Year: ", x, "<br>Tornadoes: ", y, "<br>Tornadoes Rank: ", rank)

fig <- plot_ly(x = ~x, y = ~y, type = 'scatter', mode = 'lines', text = hover_text, textposition = 'top',
             hoverinfo = 'text',  # Specify hoverinfo to show the text
             line = list(color = 'GREEN'))

fig <- fig %>% layout(
  xaxis = list(title = "Year"),
  yaxis = list(title = "Number of Tornadoes", range = c(32, max(y))),
  height = 500,  # Adjust the height as needed
  width = 800  # Adjust the width as needed
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
# Add HTML-based annotations for title and subtitle
fig <- fig %>% add_annotations(
  text = "<b>U.S. TORNADOES</b>",
  x = 0, xref = "paper",
  y = 1.05, yref = "paper",
  showarrow = FALSE,
  font = list(size = 20),
  align = "left"
)

fig <- fig %>% add_annotations(
  text = "1997 TO 2022",
  x = 0, xref = "paper",
  y = 0.97, yref = "paper",
  showarrow = FALSE,
  font = list(size = 16),
  align = "left"
)

fig
x <- df2_rank$YEAR
y <- df2_rank$`FATALITIES`
rank <- df2_rank$'FATALITIES RANK'

# Create hover text with year, temperature, and rank
hover_text <- paste("Year: ", x, "<br>Fatalities: ", y, "<br>Fatalities Rank: ", rank)

fig <- plot_ly(x = ~x, y = ~y, type = 'scatter', mode = 'lines', text = hover_text, textposition = 'top',
             hoverinfo = 'text',  # Specify hoverinfo to show the text
             line = list(color = 'BLUE'))

fig <- fig %>% layout(
  xaxis = list(title = "Year"),
  yaxis = list(title = "Number of Fatalities", range = c(32, max(y))),
  height = 500,  # Adjust the height as needed
  width = 800  # Adjust the width as needed
)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
# Add HTML-based annotations for title and subtitle
fig <- fig %>% add_annotations(
  text = "<b>U.S. FATALITIES FROM TORNADOES</b>",
  x = 0, xref = "paper",
  y = 1.05, yref = "paper",
  showarrow = FALSE,
  font = list(size = 20),
  align = "left"
)

fig <- fig %>% add_annotations(
  text = "1997 TO 2022",
  x = 0, xref = "paper",
  y = 0.97, yref = "paper",
  showarrow = FALSE,
  font = list(size = 16),
  align = "left"
)

fig
# References: https://tropical.atmos.colostate.edu/Realtime/index.php?arch&loc=global

df3 = read.csv("https://raw.githubusercontent.com/enidroman/Data_608_Knowledge_and_Visual_Analytics/main/Global%20Historical%20Tropical%20Cyclone%20Statistics.csv")
df3
##    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
df3_row<- df3[-c(1:17), ]
df3_row
##    Year Named.Storms Named.Storm.Days Hurricanes Hurricanes.Days
## 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
## 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
colnames(df3_row) <- c("YEAR", "NAMED STORMS", "NAME STORM DAYS", "HURRICAINES", "HURRICAINES DAYS", "CAT 3 AND ABOVE HURRICAINES", "CAT 3 AND ABOVE HURRICAINES DAYS", "ACCUMULATED CYCLONE ENERGY") # change column names of all the columns in the dataframe print(df)
df3_row
##    YEAR NAMED STORMS NAME STORM DAYS HURRICAINES HURRICAINES DAYS
## 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 AND ABOVE HURRICAINES CAT 3 AND ABOVE HURRICAINES DAYS
## 18                          28                            87.75
## 19                          21                            46.00
## 20                          21                            46.50
## 21                          20                            39.25
## 22                          24                            38.50
## 23                          27                            69.50
## 24                          25                            68.00
## 25                          32                            99.00
## 26                          27                            79.50
## 27                          27                            59.25
## 28                          22                            41.75
## 29                          24                            33.25
## 30                          21                            49.00
## 31                          19                            38.75
## 32                          21                            36.50
## 33                          24                            47.50
## 34                          22                            37.00
## 35                          26                            54.50
## 36                          39                            88.00
## 37                          26                            58.75
## 38                          20                            34.25
## 39                          33                            91.00
## 40                          35                            64.50
## 41                          24                            35.50
## 42                          16                            49.00
## 43                          17                            36.25
##    ACCUMULATED CYCLONE ENERGY
## 18                     1099.2
## 19                      773.1
## 20                      606.4
## 21                      677.3
## 22                      672.4
## 23                      812.0
## 24                      833.0
## 25                     1024.4
## 26                      899.6
## 27                      761.0
## 28                      568.1
## 29                      613.9
## 30                      609.6
## 31                      526.8
## 32                      573.8
## 33                      740.5
## 34                      618.5
## 35                      724.0
## 36                     1047.0
## 37                      806.5
## 38                      621.1
## 39                     1108.4
## 40                      854.8
## 41                      599.1
## 42                      621.1
## 43                      559.6
df3_index <- df3_row                        # Duplicate data
rownames(df3_index) <- 1:nrow(df3_index)    # Assign sequence to row names
df3_index 
##    YEAR NAMED STORMS NAME STORM DAYS HURRICAINES HURRICAINES DAYS
## 1  1997           97          535.25          58           220.25
## 2  1998           89          418.50          50           179.25
## 3  1999           74          317.50          39           135.50
## 4  2000           90          392.50          45           160.50
## 5  2001           88          373.50          51           162.75
## 6  2002           82          384.50          41           171.50
## 7  2003           85          418.00          50           175.00
## 8  2004           86          442.00          51           216.00
## 9  2005           96          428.75          51           189.50
## 10 2006           81          369.50          42           165.75
## 11 2007           80          303.50          44           118.75
## 12 2008           90          376.75          40           132.50
## 13 2009           85          324.75          38           115.25
## 14 2010           68          289.75          39           112.00
## 15 2011           75          335.50          39           121.00
## 16 2012           88          424.75          47           154.00
## 17 2013           90          353.25          46           127.75
## 18 2014           77          368.75          46           150.75
## 19 2015           95          500.50          54           221.00
## 20 2016           83          413.50          47           163.25
## 21 2017           84          354.75          43           135.75
## 22 2018          103          540.75          59           223.50
## 23 2019           98          449.00          55           172.25
## 24 2020          104          380.25          46           115.25
## 25 2021           94          354.75          37           119.00
## 26 2022           87          335.75          40           115.25
##    CAT 3 AND ABOVE HURRICAINES CAT 3 AND ABOVE HURRICAINES DAYS
## 1                           28                            87.75
## 2                           21                            46.00
## 3                           21                            46.50
## 4                           20                            39.25
## 5                           24                            38.50
## 6                           27                            69.50
## 7                           25                            68.00
## 8                           32                            99.00
## 9                           27                            79.50
## 10                          27                            59.25
## 11                          22                            41.75
## 12                          24                            33.25
## 13                          21                            49.00
## 14                          19                            38.75
## 15                          21                            36.50
## 16                          24                            47.50
## 17                          22                            37.00
## 18                          26                            54.50
## 19                          39                            88.00
## 20                          26                            58.75
## 21                          20                            34.25
## 22                          33                            91.00
## 23                          35                            64.50
## 24                          24                            35.50
## 25                          16                            49.00
## 26                          17                            36.25
##    ACCUMULATED CYCLONE ENERGY
## 1                      1099.2
## 2                       773.1
## 3                       606.4
## 4                       677.3
## 5                       672.4
## 6                       812.0
## 7                       833.0
## 8                      1024.4
## 9                       899.6
## 10                      761.0
## 11                      568.1
## 12                      613.9
## 13                      609.6
## 14                      526.8
## 15                      573.8
## 16                      740.5
## 17                      618.5
## 18                      724.0
## 19                     1047.0
## 20                      806.5
## 21                      621.1
## 22                     1108.4
## 23                      854.8
## 24                      599.1
## 25                      621.1
## 26                      559.6
str(df3_index)
## 'data.frame':    26 obs. of  8 variables:
##  $ YEAR                            : int  1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 ...
##  $ NAMED STORMS                    : int  97 89 74 90 88 82 85 86 96 81 ...
##  $ NAME STORM DAYS                 : num  535 418 318 392 374 ...
##  $ HURRICAINES                     : int  58 50 39 45 51 41 50 51 51 42 ...
##  $ HURRICAINES DAYS                : num  220 179 136 160 163 ...
##  $ CAT 3 AND ABOVE HURRICAINES     : int  28 21 21 20 24 27 25 32 27 27 ...
##  $ CAT 3 AND ABOVE HURRICAINES DAYS: num  87.8 46 46.5 39.2 38.5 ...
##  $ ACCUMULATED CYCLONE ENERGY      : num  1099 773 606 677 672 ...
df3_rank <- df3_index
df3_rank$'YEAR' <- as.character(df3_rank$'YEAR')
df3_rank$`NAMED STORMS` <- as.numeric(df3_rank$`NAMED STORMS`)
df3_rank$'HURRICAINES' <- as.numeric(df3_rank$'HURRICAINES')
df3_rank$'CAT 3 AND ABOVE HURRICAINES' <- as.numeric(df3_rank$'CAT 3 AND ABOVE HURRICAINES')
str(df3_rank)
## 'data.frame':    26 obs. of  8 variables:
##  $ YEAR                            : chr  "1997" "1998" "1999" "2000" ...
##  $ NAMED STORMS                    : num  97 89 74 90 88 82 85 86 96 81 ...
##  $ NAME STORM DAYS                 : num  535 418 318 392 374 ...
##  $ HURRICAINES                     : num  58 50 39 45 51 41 50 51 51 42 ...
##  $ HURRICAINES DAYS                : num  220 179 136 160 163 ...
##  $ CAT 3 AND ABOVE HURRICAINES     : num  28 21 21 20 24 27 25 32 27 27 ...
##  $ CAT 3 AND ABOVE HURRICAINES DAYS: num  87.8 46 46.5 39.2 38.5 ...
##  $ ACCUMULATED CYCLONE ENERGY      : num  1099 773 606 677 672 ...
df3_rank$'NAMED STORMS RANK' <- rank(-df3_index$`NAMED STORMS`)
df3_rank$'HURRICAINES RANK' <- rank(-df3_index$`HURRICAINES`)
df3_rank$'CAT 3 AND ABOVE HURRICAINES RANK' <- rank(-df3_index$'CAT 3 AND ABOVE HURRICAINES')
df3_rank$'ACCUMULATED CYCLONE ENERGY RANK' <- rank(-df3_index$'ACCUMULATED CYCLONE ENERGY')
df3_rank <- df3_rank[, c(1:2, 9, 3:4, 10, 5:6, 11, 7:8, 12:ncol(df3_rank))]
df3_rank
##    YEAR NAMED STORMS NAMED STORMS RANK NAME STORM DAYS HURRICAINES
## 1  1997           97               4.0          535.25          58
## 2  1998           89              11.0          418.50          50
## 3  1999           74              25.0          317.50          39
## 4  2000           90               9.0          392.50          45
## 5  2001           88              12.5          373.50          51
## 6  2002           82              20.0          384.50          41
## 7  2003           85              16.5          418.00          50
## 8  2004           86              15.0          442.00          51
## 9  2005           96               5.0          428.75          51
## 10 2006           81              21.0          369.50          42
## 11 2007           80              22.0          303.50          44
## 12 2008           90               9.0          376.75          40
## 13 2009           85              16.5          324.75          38
## 14 2010           68              26.0          289.75          39
## 15 2011           75              24.0          335.50          39
## 16 2012           88              12.5          424.75          47
## 17 2013           90               9.0          353.25          46
## 18 2014           77              23.0          368.75          46
## 19 2015           95               6.0          500.50          54
## 20 2016           83              19.0          413.50          47
## 21 2017           84              18.0          354.75          43
## 22 2018          103               2.0          540.75          59
## 23 2019           98               3.0          449.00          55
## 24 2020          104               1.0          380.25          46
## 25 2021           94               7.0          354.75          37
## 26 2022           87              14.0          335.75          40
##    HURRICAINES RANK HURRICAINES DAYS CAT 3 AND ABOVE HURRICAINES
## 1               2.0           220.25                          28
## 2               8.5           179.25                          21
## 3              23.0           135.50                          21
## 4              15.0           160.50                          20
## 5               6.0           162.75                          24
## 6              19.0           171.50                          27
## 7               8.5           175.00                          25
## 8               6.0           216.00                          32
## 9               6.0           189.50                          27
## 10             18.0           165.75                          27
## 11             16.0           118.75                          22
## 12             20.5           132.50                          24
## 13             25.0           115.25                          21
## 14             23.0           112.00                          19
## 15             23.0           121.00                          21
## 16             10.5           154.00                          24
## 17             13.0           127.75                          22
## 18             13.0           150.75                          26
## 19              4.0           221.00                          39
## 20             10.5           163.25                          26
## 21             17.0           135.75                          20
## 22              1.0           223.50                          33
## 23              3.0           172.25                          35
## 24             13.0           115.25                          24
## 25             26.0           119.00                          16
## 26             20.5           115.25                          17
##    CAT 3 AND ABOVE HURRICAINES RANK CAT 3 AND ABOVE HURRICAINES DAYS
## 1                               5.0                            87.75
## 2                              19.5                            46.00
## 3                              19.5                            46.50
## 4                              22.5                            39.25
## 5                              13.5                            38.50
## 6                               7.0                            69.50
## 7                              11.0                            68.00
## 8                               4.0                            99.00
## 9                               7.0                            79.50
## 10                              7.0                            59.25
## 11                             16.5                            41.75
## 12                             13.5                            33.25
## 13                             19.5                            49.00
## 14                             24.0                            38.75
## 15                             19.5                            36.50
## 16                             13.5                            47.50
## 17                             16.5                            37.00
## 18                              9.5                            54.50
## 19                              1.0                            88.00
## 20                              9.5                            58.75
## 21                             22.5                            34.25
## 22                              3.0                            91.00
## 23                              2.0                            64.50
## 24                             13.5                            35.50
## 25                             26.0                            49.00
## 26                             25.0                            36.25
##    ACCUMULATED CYCLONE ENERGY ACCUMULATED CYCLONE ENERGY RANK
## 1                      1099.2                             2.0
## 2                       773.1                            10.0
## 3                       606.4                            21.0
## 4                       677.3                            14.0
## 5                       672.4                            15.0
## 6                       812.0                             8.0
## 7                       833.0                             7.0
## 8                      1024.4                             4.0
## 9                       899.6                             5.0
## 10                      761.0                            11.0
## 11                      568.1                            24.0
## 12                      613.9                            19.0
## 13                      609.6                            20.0
## 14                      526.8                            26.0
## 15                      573.8                            23.0
## 16                      740.5                            12.0
## 17                      618.5                            18.0
## 18                      724.0                            13.0
## 19                     1047.0                             3.0
## 20                      806.5                             9.0
## 21                      621.1                            16.5
## 22                     1108.4                             1.0
## 23                      854.8                             6.0
## 24                      599.1                            22.0
## 25                      621.1                            16.5
## 26                      559.6                            25.0
df3_table <- datatable(df3_rank)
df3_table
library(ggplot2)
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.2.2
# Your existing ggplot code
p1 <- ggplot(df3_rank, aes(x = YEAR, y = HURRICAINES, label = HURRICAINES)) +
  geom_point(color = "#69b3a2") +
  geom_text_repel(data = df3_rank[!is.na(df3_rank$YEAR), , ]) +
  geom_segment(
    color = "#69b3a2",
    aes(
      xend = c(tail(YEAR, n = -1), NA),
      yend = c(tail(HURRICAINES, n = -1), NA)
    ),
    arrow = arrow(length = unit(0.3, "cm"))
  ) +
  labs(x = "Year", y = "Number of Hurricaines") +
  theme(legend.position = "none")

# Rotate year labels by 45 degrees
p1 <- p1 + theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Adjust height and width
p1 <- p1 + theme(
  plot.background = element_rect(fill = "white"),
  plot.margin = margin(20, 20, 20, 20)
)

# Add title and subtitle
p1 <- p1 + labs(
  title = "HURRICAINES PER YEAR",
  subtitle = "1997 to 2022"
)

# Align title to the left
p1 <- p1 + theme(
  plot.title = element_text(hjust = 0)
)

# Change plot dimensions
p1 <- p1 + theme(
  plot.background = element_rect(fill = "white"),
  plot.margin = margin(20, 20, 20, 20)
)

# Print the modified plot
p1
## Warning: Removed 1 rows containing missing values (`geom_segment()`).

# Load necessary libraries if not loaded
library(ggplot2)
library(dplyr)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.2.2
# Assuming your data is named df3_rank and has the structure mentioned

# Create a new variable "Category" for faceting
df3_rank <- df3_rank %>%
  pivot_longer(cols = c("NAMED STORMS", "HURRICAINES", "CAT 3 AND ABOVE HURRICAINES"),
               names_to = "Category", values_to = "Count")

# Define the order of the facets
category_order <- c("NAMED STORMS", "HURRICAINES", "CAT 3 AND ABOVE HURRICAINES")

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

# Plot the data using facets and add connecting lines
p <- ggplot(df3_rank, 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))

# Add title and subtitle
p <- p + labs(
  title = "Meteorological Statistics Over the Years",
  subtitle = "Yearly counts of meteorological events from 1997 to 2022"
)

# Set custom colors for the lines
p <- p + scale_color_manual(values = c("NAMED STORMS" = "blue", "HURRICAINES" = "green", "CAT 3 AND ABOVE HURRICAINES" = "red"))

# Print the modified plot
print(p)