R version 4.4.0 (2024-04-24 ucrt) -- "Puppy Cup"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> data <- read.csv("C:/Users/katoj/Downloads/CV_LatLon_21Jan_12Mar.csv/CV_LatLon_21Jan_12Mar.csv")
>   View(data)
> data
      X                 state                country      lat       lon
1     0                     0               Thailand  15.0000  101.0000
2     1                     0                  Japan  36.0000  138.0000
3     2                     0              Singapore   1.2833  103.8333
4     3                     0                  Nepal  28.1667   84.2500
5     4                     0               Malaysia   2.5000  112.5000
6     5      British Columbia                 Canada  49.2827 -123.1207
7     6       New South Wales              Australia -33.8688  151.2093
8     7              Victoria              Australia -37.8136  144.9631
9     8            Queensland              Australia -28.0167  153.4000
10    9                     0               Cambodia  11.5500  104.9167
11   10                     0              Sri Lanka   7.0000   81.0000
12   11                     0                Germany  51.0000    9.0000
13   12                     0                Finland  64.0000   26.0000
14   13                     0   United Arab Emirates  24.0000   54.0000
15   14                     0            Philippines  13.0000  122.0000
16   15                     0                  India  21.0000   78.0000
17   16                     0                  Italy  43.0000   12.0000
18   17                     0                 Sweden  63.0000   16.0000
19   18                     0                  Spain  40.0000   -4.0000
20   19       South Australia              Australia -34.9285  138.6007
21   20                     0                Belgium  50.8333    4.0000
22   21                     0                  Egypt  26.0000   30.0000
23   22 From Diamond Princess              Australia  35.4437  139.6380
24   23                     0                Lebanon  33.8547   35.8623
25   24                     0                   Iraq  33.0000   44.0000
26   25                     0                   Oman  21.0000   57.0000
27   26                     0            Afghanistan  33.0000   65.0000
28   27                     0                Bahrain  26.0275   50.5500
29   28                     0                 Kuwait  29.5000   47.7500
30   29                     0                Algeria  28.0339    1.6596
31   30                     0                Croatia  45.1000   15.2000
32   31                     0            Switzerland  46.8182    8.2275
33   32                     0                Austria  47.5162   14.5501
34   33                     0                 Israel  31.0000   35.0000
35   34                     0               Pakistan  30.3753   69.3451
36   35                     0                 Brazil -14.2350  -51.9253
37   36                     0                Georgia  42.3154   43.3569
38   37                     0                 Greece  39.0742   21.8243
39   38                     0        North Macedonia  41.6086   21.7453
40   39                     0                 Norway  60.4720    8.4689
41   40                     0                Romania  45.9432   24.9668
42   41                     0                Estonia  58.5953   25.0136
43   42                     0            Netherlands  52.1326    5.2913
44   43                     0             San Marino  43.9424   12.4578
45   44                     0                Belarus  53.7098   27.9534
46   45                     0                Iceland  64.9631  -19.0208
47   46                     0              Lithuania  55.1694   23.8813
48   47                     0                 Mexico  23.6345 -102.5528
49   48                     0            New Zealand -40.9006  174.8860
50   49                     0                Nigeria   9.0820    8.6753
51   50     Western Australia              Australia -31.9505  115.8605
52   51                     0                Ireland  53.1424   -7.6921
53   52                     0             Luxembourg  49.8153    6.1296
54   53                     0                 Monaco  43.7333    7.4167
55   54                     0                  Qatar  25.3548   51.1839
56   55                     0                Ecuador  -1.8312  -78.1834
57   56                     0             Azerbaijan  40.1431   47.5769
58   57                     0                Armenia  40.0691   45.0382
59   58                     0     Dominican Republic  18.7357  -70.1627
60   59                     0              Indonesia  -0.7893  113.9213
61   60                     0               Portugal  39.3999   -8.2245
62   61                     0                Andorra  42.5063    1.5218
63   62              Tasmania              Australia -41.4545  145.9707
64   63                     0                 Latvia  56.8796   24.6032
65   64                     0                Morocco  31.7917   -7.0926
66   65                     0           Saudi Arabia  24.0000   45.0000
67   66                     0                Senegal  14.4974  -14.4524
68   67                     0              Argentina -38.4161  -63.6167
69   68                     0                  Chile -35.6751  -71.5430
70   69                     0                 Jordan  31.2400   36.5100
71   70                     0                Ukraine  48.3794   31.1656
72   71                     0                Hungary  47.1625   19.5033
73   72    Northern Territory              Australia -12.4634  130.8456
74   73                     0          Liechtenstein  47.1400    9.5500
75   74                     0                 Poland  51.9194   19.1451
76   75                     0                Tunisia  34.0000    9.0000
77   76                     0 Bosnia and Herzegovina  43.9159   17.6791
78   77                     0               Slovenia  46.1512   14.9955
79   78                     0           South Africa -30.5595   22.9375
80   79                     0                 Bhutan  27.5142   90.4336
81   80                     0               Cameroon   3.8480   11.5021
82   81                     0               Colombia   4.5709  -74.2973
83   82                     0             Costa Rica   9.7489  -83.7534
84   83                     0                   Peru  -9.1900  -75.0152
85   84                     0                 Serbia  44.0165   21.0059
86   85                     0               Slovakia  48.6690   19.6990
87   86                     0                   Togo   8.6195    0.8248
88   87                     0          French Guiana   3.9339  -53.1258
89   88                     0                  Malta  35.9375   14.3754
90   89                     0             Martinique  14.6415  -61.0242
91   90                     0               Bulgaria  42.7339   25.4858
92   91                     0               Maldives   3.2028   73.2207
93   92                     0             Bangladesh  23.6850   90.3563
94   93                     0               Paraguay -23.4425  -58.4438
95   94               Ontario                 Canada  51.2538  -85.3232
96   95               Alberta                 Canada  53.9333 -116.5765
97   96                Quebec                 Canada  52.9399  -73.5491
98   97                     0                Albania  41.1533   20.1683
99   98                     0                 Cyprus  35.1264   33.4299
100  99                     0                 Brunei   4.5353  114.7277
101 100            Washington                     US  47.4009 -121.4905
102 101              New York                     US  42.1657  -74.9481
103 102            California                     US  36.1162 -119.6816
104 103         Massachusetts                     US  42.2302  -71.5301
105 104      Diamond Princess                     US  35.4437  139.6380
106 105        Grand Princess                     US  37.6489 -122.6655
107 106               Georgia                     US  33.0406  -83.6431
108 107              Colorado                     US  39.0598 -105.3111
109 108               Florida                     US  27.7663  -81.6868
110 109            New Jersey                     US  40.2989  -74.5210
111 110                Oregon                     US  44.5720 -122.0709
       date confirmed recovered death
1   1/22/20         2         0     0
2   1/22/20         2         0     0
3   1/22/20         0         0     0
4   1/22/20         0         0     0
5   1/22/20         0         0     0
6   1/22/20         0         0     0
7   1/22/20         0         0     0
8   1/22/20         0         0     0
9   1/22/20         0         0     0
10  1/22/20         0         0     0
11  1/22/20         0         0     0
12  1/22/20         0         0     0
13  1/22/20         0         0     0
14  1/22/20         0         0     0
15  1/22/20         0         0     0
16  1/22/20         0         0     0
17  1/22/20         0         0     0
18  1/22/20         0         0     0
19  1/22/20         0         0     0
20  1/22/20         0         0     0
21  1/22/20         0         0     0
22  1/22/20         0         0     0
23  1/22/20         0         0     0
24  1/22/20         0         0     0
25  1/22/20         0         0     0
26  1/22/20         0         0     0
27  1/22/20         0         0     0
28  1/22/20         0         0     0
29  1/22/20         0         0     0
30  1/22/20         0         0     0
31  1/22/20         0         0     0
32  1/22/20         0         0     0
33  1/22/20         0         0     0
34  1/22/20         0         0     0
35  1/22/20         0         0     0
36  1/22/20         0         0     0
37  1/22/20         0         0     0
38  1/22/20         0         0     0
39  1/22/20         0         0     0
40  1/22/20         0         0     0
41  1/22/20         0         0     0
42  1/22/20         0         0     0
43  1/22/20         0         0     0
44  1/22/20         0         0     0
45  1/22/20         0         0     0
46  1/22/20         0         0     0
47  1/22/20         0         0     0
48  1/22/20         0         0     0
49  1/22/20         0         0     0
50  1/22/20         0         0     0
51  1/22/20         0         0     0
52  1/22/20         0         0     0
53  1/22/20         0         0     0
54  1/22/20         0         0     0
55  1/22/20         0         0     0
56  1/22/20         0         0     0
57  1/22/20         0         0     0
58  1/22/20         0         0     0
59  1/22/20         0         0     0
60  1/22/20         0         0     0
61  1/22/20         0         0     0
62  1/22/20         0         0     0
63  1/22/20         0         0     0
64  1/22/20         0         0     0
65  1/22/20         0         0     0
66  1/22/20         0         0     0
67  1/22/20         0         0     0
68  1/22/20         0         0     0
69  1/22/20         0         0     0
70  1/22/20         0         0     0
71  1/22/20         0         0     0
72  1/22/20         0         0     0
73  1/22/20         0         0     0
74  1/22/20         0         0     0
75  1/22/20         0         0     0
76  1/22/20         0         0     0
77  1/22/20         0         0     0
78  1/22/20         0         0     0
79  1/22/20         0         0     0
80  1/22/20         0         0     0
81  1/22/20         0         0     0
82  1/22/20         0         0     0
83  1/22/20         0         0     0
84  1/22/20         0         0     0
85  1/22/20         0         0     0
86  1/22/20         0         0     0
87  1/22/20         0         0     0
88  1/22/20         0         0     0
89  1/22/20         0         0     0
90  1/22/20         0         0     0
91  1/22/20         0         0     0
92  1/22/20         0         0     0
93  1/22/20         0         0     0
94  1/22/20         0         0     0
95  1/22/20         0         0     0
96  1/22/20         0         0     0
97  1/22/20         0         0     0
98  1/22/20         0         0     0
99  1/22/20         0         0     0
100 1/22/20         0         0     0
101 1/22/20         0         0     0
102 1/22/20         0         0     0
103 1/22/20         0         0     0
104 1/22/20         0         0     0
105 1/22/20         0         0     0
106 1/22/20         0         0     0
107 1/22/20         0         0     0
108 1/22/20         0         0     0
109 1/22/20         0         0     0
110 1/22/20         0         0     0
111 1/22/20         0         0     0
 [ reached 'max' / getOption("max.print") -- omitted 20595 rows ]
> library(dplyr)

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(lubridate)

Attaching package: ‘lubridate’

The following objects are masked from ‘package:base’:

    date, intersect, setdiff, union

> library(tidyr)
> library(ggplot2)
> library(sf)
Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
> library(leaflet)
> library(rworldmap)
Loading required package: sp
### Welcome to rworldmap ###
For a short introduction type : 	 vignette('rworldmap')
> 
> data <- data %>% 
+     mutate(
+         state = ifelse(state == "", "Unknown", state),
+         date = mdy(date),
+         lat = as.numeric(lat),
+         lon = as.numeric(lon)
+     ) %>% 
+     filter(
+         lat >= -90 & lat <= 90 & 
+             lon >= -180 & lon <= 180 & 
+             !(confirmed == 0 & recovered == 0 & death == 0)
+     )
> 
> head(data)
    X     state      country     lat      lon       date confirmed recovered
1   0         0     Thailand 15.0000 101.0000 2020-01-22         2         0
2   1         0        Japan 36.0000 138.0000 2020-01-22         2         0
3 156     Hubei        China 30.9756 112.2707 2020-01-22       444        28
4 158         0 Korea, South 36.0000 128.0000 2020-01-22         1         0
5 160 Guangdong        China 23.3417 113.4244 2020-01-22        26         0
6 161     Henan        China 33.8820 113.6140 2020-01-22         5         0
  death
1     0
2     0
3    17
4     0
5     0
6     0
> str(data)
'data.frame':	4904 obs. of  9 variables:
 $ X        : int  0 1 156 158 160 161 162 163 164 165 ...
 $ state    : chr  "0" "0" "Hubei" "0" ...
 $ country  : chr  "Thailand" "Japan" "China" "Korea, South" ...
 $ lat      : num  15 36 31 36 23.3 ...
 $ lon      : num  101 138 112 128 113 ...
 $ date     : Date, format: "2020-01-22" "2020-01-22" ...
 $ confirmed: int  2 2 444 1 26 5 10 4 1 2 ...
 $ recovered: int  0 0 28 0 0 0 0 0 0 0 ...
 $ death    : int  0 0 17 0 0 0 0 0 0 0 ...
> summary(data)
       X            state             country               lat        
 Min.   :    0   Length:4904        Length:4904        Min.   :-41.45  
 1st Qu.: 8312   Class :character   Class :character   1st Qu.: 24.97  
 Median :14786   Mode  :character   Mode  :character   Median : 35.13  
 Mean   :13164                                         Mean   : 30.79  
 3rd Qu.:18348                                         3rd Qu.: 41.74  
 Max.   :20705                                         Max.   : 64.96  
      lon               date              confirmed         recovered      
 Min.   :-157.86   Min.   :2020-01-22   Min.   :    1.0   Min.   :    0.0  
 1st Qu.:  -4.00   1st Qu.:2020-02-11   1st Qu.:    2.0   1st Qu.:    0.0  
 Median :  85.24   Median :2020-02-27   Median :   11.0   Median :    1.0  
 Mean   :  42.60   Mean   :2020-02-23   Mean   :  607.4   Mean   :  216.2  
 3rd Qu.: 113.94   3rd Qu.:2020-03-07   3rd Qu.:  108.0   3rd Qu.:   16.0  
 Max.   : 174.89   Max.   :2020-03-12   Max.   :67781.0   Max.   :50318.0  
     death        
 Min.   :   0.00  
 1st Qu.:   0.00  
 Median :   0.00  
 Mean   :  18.77  
 3rd Qu.:   1.00  
 Max.   :3056.00  
> 
> agg_data <- data %>%
+     group_by(country) %>%
+     summarise(
+         total_confirmed = sum(confirmed),
+         total_recovered = sum(recovered),
+         total_deaths = sum(death)
+     ) %>%
+     ungroup()
> 
> top_countries_confirmed <- agg_data %>% 
+     arrange(desc(total_confirmed)) %>% 
+     head(10)
> 
> ggplot(top_countries_confirmed, aes(x=reorder(country, total_confirmed), y=total_confirmed)) +
+     geom_bar(stat="identity", fill="steelblue") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Confirmed Cases", x="Country", y="Total Confirmed Cases")
> 
> top_countries_deaths <- agg_data %>% 
+     arrange(desc(total_deaths)) %>% 
+     head(10)
> 
> ggplot(top_countries_deaths, aes(x=reorder(country, total_deaths), y=total_deaths)) +
+     geom_bar(stat="identity", fill="red") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Deaths", x="Country", y="Total Deaths")
> 
> top_countries_recovered <- agg_data %>% 
+     arrange(desc(total_recovered)) %>% 
+     head(10)
> 
> ggplot(top_countries_recovered, aes(x=reorder(country, total_recovered), y=total_recovered)) +
+     geom_bar(stat="identity", fill="green") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Recovered Cases", x="Country", y="Total Recovered Cases")
> 
> summary_stats <- agg_data %>%
+     summarise(
+         total_confirmed = sum(total_confirmed),
+         total_recovered = sum(total_recovered),
+         total_deaths = sum(total_deaths),
+         mean_confirmed = mean(total_confirmed),
+         mean_recovered = mean(total_recovered),
+         mean_deaths = mean(total_deaths)
+     )
> 
> print(summary_stats)
# A tibble: 1 × 6
  total_confirmed total_recovered total_deaths mean_confirmed mean_recovered
            <int>           <int>        <int>          <dbl>          <dbl>
1         2978672         1060292        92035        2978672        1060292
# ℹ 1 more variable: mean_deaths <dbl>
> 
> ggplot(data, aes(x = lon, y = lat)) +
+     geom_hex(bins = 30) +
+     scale_fill_gradient(low = "blue", high = "red") +
+     labs(title="Heatmap of COVID-19 Cases",
+          x="Longitude", y="Latitude")
> 
> map_data <- joinCountryData2Map(agg_data, joinCode = "NAME", nameJoinColumn = "country")
110 codes from your data successfully matched countries in the map
6 codes from your data failed to match with a country code in the map
133 codes from the map weren't represented in your data
> 
> par(mar = c(0, 0, 2, 0))
> mapCountryData(map_data, nameColumnToPlot = "total_confirmed", 
+                mapTitle = "Global Distribution of COVID-19 Confirmed Cases", 
+                colourPalette = "heat")
> 
> data_sf <- st_as_sf(data, coords = c("lon", "lat"), crs = 4326)
> 
> leaflet(data_sf) %>%
+     addTiles() %>%
+     addCircleMarkers(
+         radius = ~log1p(confirmed+1),
+         color = "blue",
+         popup = ~paste0("<strong>Country: </strong>", country, "<br>",
+                         "<strong>Confirmed Cases: </strong>", confirmed, "<br>",
+                         "<strong>Recovered: </strong>", recovered, "<br>",
+                         "<strong>Deaths: </strong>", death)
+     ) %>%
+     addLegend("bottomright", 
+               colors=c("blue"),
+               labels=c("Confirmed Cases"),
+               opacity=0.5,
+               title="COVID-19 Cases")
> 
> leaflet(data_sf) %>%
+     addTiles() %>%
+     addCircleMarkers(
+         radius = ~log1p(death+1),
+         color = "red",
+         popup = ~paste0("<strong>Country: </strong>", country, "<br>",
+                         "<strong>Confirmed Cases: </strong>", confirmed, "<br>",
+                         "<strong>Recovered: </strong>", recovered, "<br>",
+                         "<strong>Deaths: </strong>", death)
+     ) %>%
+     addLegend("bottomright", 
+               colors=c("red"),
+               labels=c("Deaths"),
+               opacity=0.5,
+               title="COVID-19 Deaths")
> 
> leaflet(data_sf) %>%
+     addTiles() %>%
+     addCircleMarkers(
+         radius = ~log1p(recovered+1),
+         color = "green",
+         popup = ~paste0("<strong>Country: </strong>", country, "<br>",
+                         "<strong>Confirmed Cases: </strong>", confirmed, "<br>",
+                         "<strong>Recovered: </strong>", recovered, "<br>",
+                         "<strong>Deaths: </strong>", death)
+     ) %>%
+     addLegend("bottomright", 
+               colors=c("green"),
+               labels=c("Recovered"),
+               opacity=0.5,
+               title="COVID-19 Recovered")
> 
> m <- leaflet() %>%
Warning message:
In doTryCatch(return(expr), name, parentenv, handler) :
  display list redraw incomplete
+     addTiles() %>%
+     addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
> 
> print(m)
> m
> m
> m
> install.packages("htmlwidgets")
Error in install.packages : Updating loaded packages
> install.packages("htmlwidgets")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/katoj/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/htmlwidgets_1.6.4.zip'
Content type 'application/zip' length 813387 bytes (794 KB)
downloaded 794 KB

package ‘htmlwidgets’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\katoj\AppData\Local\Temp\RtmpUJ58PB\downloaded_packages
> # Load necessary libraries
> library(dplyr)
> library(lubridate)
> library(tidyr)
> library(ggplot2)
> library(sf)
> library(leaflet)
> library(rworldmap)
> library(htmlwidgets)  # For saving Leaflet maps as HTML files
> 
> # Preprocess the data
> data <- data %>% 
+     mutate(
+         state = ifelse(state == "", "Unknown", state),
+         date = mdy(date),
+         lat = as.numeric(lat),
+         lon = as.numeric(lon)
+     ) %>% 
+     filter(
+         lat >= -90 & lat <= 90 & 
+             lon >= -180 & lon <= 180 & 
+             !(confirmed == 0 & recovered == 0 & death == 0)
+     )
Warning message:
There was 1 warning in `mutate()`.
ℹ In argument: `date = mdy(date)`.
Caused by warning:
! All formats failed to parse. No formats found. 
> 
> # Inspect the cleaned data
> head(data)
    X     state      country     lat      lon date confirmed recovered death
1   0         0     Thailand 15.0000 101.0000 <NA>         2         0     0
2   1         0        Japan 36.0000 138.0000 <NA>         2         0     0
3 156     Hubei        China 30.9756 112.2707 <NA>       444        28    17
4 158         0 Korea, South 36.0000 128.0000 <NA>         1         0     0
5 160 Guangdong        China 23.3417 113.4244 <NA>        26         0     0
6 161     Henan        China 33.8820 113.6140 <NA>         5         0     0
> str(data)
'data.frame':	4904 obs. of  9 variables:
 $ X        : int  0 1 156 158 160 161 162 163 164 165 ...
 $ state    : chr  "0" "0" "Hubei" "0" ...
 $ country  : chr  "Thailand" "Japan" "China" "Korea, South" ...
 $ lat      : num  15 36 31 36 23.3 ...
 $ lon      : num  101 138 112 128 113 ...
 $ date     : Date, format: NA NA ...
 $ confirmed: int  2 2 444 1 26 5 10 4 1 2 ...
 $ recovered: int  0 0 28 0 0 0 0 0 0 0 ...
 $ death    : int  0 0 17 0 0 0 0 0 0 0 ...
> summary(data)
       X            state             country               lat        
 Min.   :    0   Length:4904        Length:4904        Min.   :-41.45  
 1st Qu.: 8312   Class :character   Class :character   1st Qu.: 24.97  
 Median :14786   Mode  :character   Mode  :character   Median : 35.13  
 Mean   :13164                                         Mean   : 30.79  
 3rd Qu.:18348                                         3rd Qu.: 41.74  
 Max.   :20705                                         Max.   : 64.96  
                                                                       
      lon               date        confirmed         recovered      
 Min.   :-157.86   Min.   :NA     Min.   :    1.0   Min.   :    0.0  
 1st Qu.:  -4.00   1st Qu.:NA     1st Qu.:    2.0   1st Qu.:    0.0  
 Median :  85.24   Median :NA     Median :   11.0   Median :    1.0  
 Mean   :  42.60   Mean   :NaN    Mean   :  607.4   Mean   :  216.2  
 3rd Qu.: 113.94   3rd Qu.:NA     3rd Qu.:  108.0   3rd Qu.:   16.0  
 Max.   : 174.89   Max.   :NA     Max.   :67781.0   Max.   :50318.0  
                   NA's   :4904                                      
     death        
 Min.   :   0.00  
 1st Qu.:   0.00  
 Median :   0.00  
 Mean   :  18.77  
 3rd Qu.:   1.00  
 Max.   :3056.00  
                  
> 
> # Aggregate data by country
> agg_data <- data %>%
+     group_by(country) %>%
+     summarise(
+         total_confirmed = sum(confirmed),
+         total_recovered = sum(recovered),
+         total_deaths = sum(death)
+     ) %>%
+     ungroup()
> 
> # Plotting top 10 countries by confirmed cases
> top_countries_confirmed <- agg_data %>% 
+     arrange(desc(total_confirmed)) %>% 
+     head(10)
> 
> ggplot(top_countries_confirmed, aes(x=reorder(country, total_confirmed), y=total_confirmed)) +
+     geom_bar(stat="identity", fill="steelblue") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Confirmed Cases", x="Country", y="Total Confirmed Cases")
> 
> # Plotting top 10 countries by deaths
> top_countries_deaths <- agg_data %>% 
+     arrange(desc(total_deaths)) %>% 
+     head(10)
> 
> ggplot(top_countries_deaths, aes(x=reorder(country, total_deaths), y=total_deaths)) +
+     geom_bar(stat="identity", fill="red") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Deaths", x="Country", y="Total Deaths")
> 
> # Plotting top 10 countries by recovered cases
> top_countries_recovered <- agg_data %>% 
+     arrange(desc(total_recovered)) %>% 
+     head(10)
> 
> ggplot(top_countries_recovered, aes(x=reorder(country, total_recovered), y=total_recovered)) +
+     geom_bar(stat="identity", fill="green") +
+     coord_flip() +
+     labs(title="Top 10 Countries by Recovered Cases", x="Country", y="Total Recovered Cases")
> 
> # Summary statistics
> summary_stats <- agg_data %>%
+     summarise(
+         total_confirmed = sum(total_confirmed),
+         total_recovered = sum(total_recovered),
+         total_deaths = sum(total_deaths),
+         mean_confirmed = mean(total_confirmed),
+         mean_recovered = mean(total_recovered),
+         mean_deaths = mean(total_deaths)
+     )
> 
> print(summary_stats)
# A tibble: 1 × 6
  total_confirmed total_recovered total_deaths mean_confirmed mean_recovered
            <int>           <int>        <int>          <dbl>          <dbl>
1         2978672         1060292        92035        2978672        1060292
# ℹ 1 more variable: mean_deaths <dbl>
> 
> # Heatmap of cases
> ggplot(data, aes(x = lon, y = lat)) +
+     geom_hex(bins = 30) +
+     scale_fill_gradient(low = "blue", high = "red") +
+     labs(title="Heatmap of COVID-19 Cases",
+          x="Longitude", y="Latitude")
> 
> # World Map visualization
> map_data <- joinCountryData2Map(agg_data, joinCode = "NAME", nameJoinColumn = "country")
110 codes from your data successfully matched countries in the map
6 codes from your data failed to match with a country code in the map
133 codes from the map weren't represented in your data
> 
> par(mar = c(0, 0, 2, 0))
> mapCountryData(map_data, nameColumnToPlot = 'total_confirmed', 
+                mapTitle = 'Global Distribution of COVID-19 Confirmed Cases', 
+                colourPalette = 'heat')
> 
> # Geospatial interactive maps
> data_sf <- st_as_sf(data, coords = c("lon", "lat"), crs = 4326)
> 
> # Interactive Map of Confirmed Cases
> m_confirmed <- leaflet(data_sf) %>%
+     addTiles() %>%
+     addCircleMarkers(
+         radius = ~log1p(confirmed+1),
+         color = "blue",
+         popup = ~paste0("<strong>Country: </strong>", country, "<br>",
+                         "<strong>Confirmed Cases: </strong>", confirmed, "<br>",
+                         "<strong>Recovered: </strong>", recovered, "<br>",
+                         "<strong>Deaths: </strong>", death)
+     ) %>%
+     addLegend("bottomright", 
+               colors = c("blue"),
+               labels = c("Confirmed Cases"),
+               opacity = 0.5,
+               title = "COVID-19 Cases")
> 
> saveWidget(m_confirmed, "Confirmed_Cases_Map.html")
> 
> # Interactive Map of Death Cases
> m_deaths <- leaflet(data_sf) %>%
+     addTiles() %>%
+     addCircleMarkers(
+         radius = ~log1p(death+1),
+         color = "red",
+         popup = ~paste0("<strong>Country: </strong>", country, "<br>",
+                         "<strong>Confirmed Cases: </strong>", confirmed, "<br>",
+                         "<strong>Recovered: </strong>", recovered, "<br>",
+                         "<strong>Deaths: </strong>", death)
+     ) %>%
+     addLegend("bottomright", 
+               colors = c("red"),
+               labels = c("Deaths"),
+               opacity = 0.5,
+               title="COVID-19 Deaths")
> 
> saveWidget(m_deaths, "Death_Cases_Map.html")
> 
> # Interactive Map of Recovered Cases
> 
> View(m_deaths)
> View(m_deaths)
> View(m_deaths)
> View(m_deaths)
> # Install Prophet
> install.packages("prophet")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/katoj/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
also installing the dependencies ‘backports’, ‘abind’, ‘tensorA’, ‘distributional’, ‘ps’, ‘checkmate’, ‘matrixStats’, ‘posterior’, ‘callr’, ‘processx’, ‘inline’, ‘gridExtra’, ‘loo’, ‘pkgbuild’, ‘QuickJSR’, ‘desc’, ‘dygraphs’, ‘extraDistr’, ‘RcppParallel’, ‘rstan’, ‘rstantools’, ‘StanHeaders’, ‘BH’, ‘RcppEigen’


  There is a binary version available but the source version is later:
          binary source needs_compilation
backports  1.4.1  1.5.0              TRUE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/backports_1.4.1.zip'
Content type 'application/zip' length 104628 bytes (102 KB)
downloaded 102 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/abind_1.4-5.zip'
Content type 'application/zip' length 64252 bytes (62 KB)
downloaded 62 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/tensorA_0.36.2.1.zip'
Content type 'application/zip' length 227784 bytes (222 KB)
downloaded 222 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/distributional_0.4.0.zip'
Content type 'application/zip' length 432261 bytes (422 KB)
downloaded 422 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/ps_1.7.6.zip'
Content type 'application/zip' length 557978 bytes (544 KB)
downloaded 544 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/checkmate_2.3.1.zip'
Content type 'application/zip' length 746690 bytes (729 KB)
downloaded 729 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/matrixStats_1.3.0.zip'
Content type 'application/zip' length 551748 bytes (538 KB)
downloaded 538 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/posterior_1.5.0.zip'
Content type 'application/zip' length 976398 bytes (953 KB)
downloaded 953 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/callr_3.7.6.zip'
Content type 'application/zip' length 474064 bytes (462 KB)
downloaded 462 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/processx_3.8.4.zip'
Content type 'application/zip' length 688455 bytes (672 KB)
downloaded 672 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/inline_0.3.19.zip'
Content type 'application/zip' length 131722 bytes (128 KB)
downloaded 128 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/gridExtra_2.3.zip'
Content type 'application/zip' length 1109361 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/loo_2.7.0.zip'
Content type 'application/zip' length 1881387 bytes (1.8 MB)
downloaded 1.8 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/pkgbuild_1.4.4.zip'
Content type 'application/zip' length 203956 bytes (199 KB)
downloaded 199 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/QuickJSR_1.1.3.zip'
Content type 'application/zip' length 1430820 bytes (1.4 MB)
downloaded 1.4 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/desc_1.4.3.zip'
Content type 'application/zip' length 336211 bytes (328 KB)
downloaded 328 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/dygraphs_1.1.1.6.zip'
Content type 'application/zip' length 445174 bytes (434 KB)
downloaded 434 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/extraDistr_1.10.0.zip'
Content type 'application/zip' length 947846 bytes (925 KB)
downloaded 925 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/RcppParallel_5.1.7.zip'
Content type 'application/zip' length 1293757 bytes (1.2 MB)
downloaded 1.2 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rstan_2.32.6.zip'
Content type 'application/zip' length 2689817 bytes (2.6 MB)
downloaded 2.6 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/rstantools_2.4.0.zip'
Content type 'application/zip' length 178181 bytes (174 KB)
downloaded 174 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/StanHeaders_2.32.8.zip'
Content type 'application/zip' length 3174227 bytes (3.0 MB)
downloaded 3.0 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/BH_1.84.0-0.zip'
Content type 'application/zip' length 21468602 bytes (20.5 MB)
downloaded 20.5 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/RcppEigen_0.3.4.0.0.zip'
Content type 'application/zip' length 2591058 bytes (2.5 MB)
downloaded 2.5 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.4/prophet_1.0.zip'
Content type 'application/zip' length 1364950 bytes (1.3 MB)
downloaded 1.3 MB

package ‘backports’ successfully unpacked and MD5 sums checked
package ‘abind’ successfully unpacked and MD5 sums checked
package ‘tensorA’ successfully unpacked and MD5 sums checked
package ‘distributional’ successfully unpacked and MD5 sums checked
package ‘ps’ successfully unpacked and MD5 sums checked
package ‘checkmate’ successfully unpacked and MD5 sums checked
package ‘matrixStats’ successfully unpacked and MD5 sums checked
package ‘posterior’ successfully unpacked and MD5 sums checked
package ‘callr’ successfully unpacked and MD5 sums checked
package ‘processx’ successfully unpacked and MD5 sums checked
package ‘inline’ successfully unpacked and MD5 sums checked
package ‘gridExtra’ successfully unpacked and MD5 sums checked
package ‘loo’ successfully unpacked and MD5 sums checked
package ‘pkgbuild’ successfully unpacked and MD5 sums checked
package ‘QuickJSR’ successfully unpacked and MD5 sums checked
package ‘desc’ successfully unpacked and MD5 sums checked
package ‘dygraphs’ successfully unpacked and MD5 sums checked
package ‘extraDistr’ successfully unpacked and MD5 sums checked
package ‘RcppParallel’ successfully unpacked and MD5 sums checked
package ‘rstan’ successfully unpacked and MD5 sums checked
package ‘rstantools’ successfully unpacked and MD5 sums checked
package ‘StanHeaders’ successfully unpacked and MD5 sums checked
package ‘BH’ successfully unpacked and MD5 sums checked
package ‘RcppEigen’ successfully unpacked and MD5 sums checked
package ‘prophet’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\katoj\AppData\Local\Temp\RtmpUJ58PB\downloaded_packages
> 
> ### Load Required Libraries
> 
> # Load the required libraries:
> library(prophet)
Loading required package: Rcpp
Loading required package: rlang
> 
> ### Prepare the Data
> 
> # Aggregate the data by date to get the total confirmed cases for each date.
> # Preprocess the data:
> time_series_data <- data %>%
+     group_by(date) %>%
+     summarise(total_confirmed = sum(confirmed)) %>%
+     ungroup()
> 
> # Inspect the data
> head(time_series_data)
# A tibble: 1 × 2
  date   total_confirmed
  <date>           <int>
1 NA             2978672
> 
> ### Prepare the Data for Prophet
> 
> # Rename the columns to ds (date) and y (value) as required by Prophet:
> prophet_data <- time_series_data %>%
+     rename(ds = date, y = total_confirmed)
> 
> # Inspect the renamed data
> head(prophet_data)
# A tibble: 1 × 2
  ds           y
  <date>   <int>
1 NA     2978672
> 
> ### Fit the Prophet Model
> 
> # Initialize and fit the model
> model <- prophet(prophet_data)
Error in fit.prophet(m, df, ...) : Dataframe has less than 2 non-NA rows.
> # Remove rows with NA values
> prophet_data <- na.omit(prophet_data)
> 
> # Check if there are enough rows
> if (nrow(prophet_data) < 2) {
+     print("Error: Not enough data points to fit the model")
+ } else {
+     # Fit the Prophet model
+     model <- prophet(prophet_data)
+ }
[1] "Error: Not enough data points to fit the model"
> 
> prophet_data
# A tibble: 0 × 2
# ℹ 2 variables: ds <date>, y <int>
> view(prophet_data)
Error in view(prophet_data) : could not find function "view"
> summary(prophet_data)
       ds            y      
 Min.   :NA    Min.   : NA  
 1st Qu.:NA    1st Qu.: NA  
 Median :NA    Median : NA  
 Mean   :NaN   Mean   :NaN  
 3rd Qu.:NA    3rd Qu.: NA  
 Max.   :NA    Max.   : NA  
> # Ensure Required Libraries are Installed and Loaded:
> install.packages("prophet")
Error in install.packages : Updating loaded packages
> install.packages("dplyr")
Error in install.packages : Updating loaded packages
> 
> library(prophet)
> library(dplyr)
> 
> # Prepare Your Dataset:
> # Aggregate data by date.
> # Rename columns as required by prophet (i.e., ds for date and y for numeric values).
> 
> # Assuming data is your original dataset and has columns ‘date’ and ‘confirmed’.
> time_series_data <- data %>%
+     group_by(date) %>%
+     summarise(total_confirmed = sum(confirmed)) %>%
+     ungroup()
> 
> # Rename columns to fit Prophet requirements
> prophet_data <- time_series_data %>%
+     rename(ds = date, y = total_confirmed)
> 
> # Inspect the prepared data
> head(prophet_data)
# A tibble: 1 × 2
  ds           y
  <date>   <int>
1 NA     2978672
> 
> # Check for NA Values and Handle Them:
> prophet_data <- na.omit(prophet_data)
> 
> # Ensure there is enough data after removing NAs
> if (nrow(prophet_data) < 2) {
+     stop("Error: Not enough data points to fit the model")
+ }
Error: Error: Not enough data points to fit the model
> install.packages("dplyr")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
  package ‘dplyr’ is in use and will not be installed
> install.packages("prophet")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
  package ‘prophet’ is in use and will not be installed
> # Install and load required packages
> install.packages("prophet")
Error in install.packages : Updating loaded packages
> install.packages("dplyr")
Error in install.packages : Updating loaded packages
> library(prophet)
> library(dplyr)
> 
> # Preparing the data
> time_series_data <- data %>%
+     group_by(date) %>%
+     summarise(total_confirmed = sum(confirmed)) %>%
+     ungroup()
> 
> prophet_data <- time_series_data %>%
+     rename(ds = date, y = total_confirmed)
> 
> # Removing NA values
> prophet_data <- na.omit(prophet_data)
> 
> # Ensure dataset has sufficient data points
> if (nrow(prophet_data) < 10) {
+     stop("Error: Not enough data points to fit the model")
+ }
Error: Error: Not enough data points to fit the model
> install.packages("dplyr")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
  package ‘dplyr’ is in use and will not be installed
> install.packages("prophet")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Warning in install.packages :
  package ‘prophet’ is in use and will not be installed