library(plotly)
## 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
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2
## ──
## ✔ tibble  3.2.1     ✔ dplyr   1.1.2
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 0.5.2
## ✔ purrr   1.0.2
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
df <- read.csv("https://raw.githubusercontent.com/tonyCUNY/tonyCUNY/main/Count.csv")
head(df)
##   Leading.Production.Country Critical.Mineral Relationship
## 1                  Australia         Aluminum         Ally
## 2                      China         Antimony   Competitor
## 3                       Peru          Arsenic      Neutral
## 4                      India           Barite         Ally
## 5              United States        Beryllium         Ally
## 6                      China          Bismuth   Competitor
df2 <- df |> 
        group_by(Leading.Production.Country) |> 
        summarise(Country_Count = n(),
            Combined_Mineral = paste(unique(Critical.Mineral), collapse = ", "),
            Relationship = first(Relationship))
df2
## # A tibble: 10 × 4
##    Leading.Production.Country Country_Count Combined_Mineral        Relationship
##    <chr>                              <int> <chr>                   <chr>       
##  1 Australia                              3 Aluminum, Lithium, Zir… Ally        
##  2 Brazil                                 1 Niobium                 Ally        
##  3 China                                 16 Antimony, Bismuth, Flu… Competitor  
##  4 Congo (Kinshasa)                       2 Cobalt, Tantalum        Neutral     
##  5 India                                  1 Barite                  Ally        
##  6 Indonesia                              1 Nickel                  Neutral     
##  7 Peru                                   1 Arsenic                 Neutral     
##  8 Russia                                 1 Palladium               Competitor  
##  9 South Africa                           3 Chromium, Manganese, P… Neutral     
## 10 United States                          1 Beryllium               Ally
write.csv(df2, file = "df2.csv", row.names = FALSE)
df3 <- read.csv("https://raw.githubusercontent.com/tonyCUNY/tonyCUNY/main/Count2.csv")
head(df3)
##   Primary.import.source Critical.mineral Relationship
## 1               Jamaica         Aluminum         Ally
## 2                 China         Antimony   Competitor
## 3                 China          Arsenic   Competitor
## 4                 China           Barite   Competitor
## 5            Kazakhstan        Beryllium      Neutral
## 6                 China          Bismuth   Competitor
df4 <- df3 |> 
        group_by(Primary.import.source) |> 
        summarise(Country_Count = n(),
            Combined_Mineral = paste(unique(Critical.mineral), collapse = ", "),
            Relationship = first(Relationship))
df4
## # A tibble: 16 × 4
##    Primary.import.source Country_Count Combined_Mineral             Relationship
##    <chr>                         <int> <chr>                        <chr>       
##  1 Argentina                         1 Lithium                      Ally        
##  2 Brazil                            1 Niobium                      Ally        
##  3 Canada                            4 Nickel, Tellurium, Vanadium… Ally        
##  4 China                            10 Antimony, Arsenic, Barite, … Competitor  
##  5 Europe                            1 Scandium                     Ally        
##  6 Gabon                             1 Manganese                    Neutral     
##  7 Israel                            1 Magnesium                    Ally        
##  8 Jamaica                           1 Aluminum                     Ally        
##  9 Japan                             1 Titanium                     Ally        
## 10 Kazakhstan                        1 Beryllium                    Neutral     
## 11 Mexico                            1 Fluorspar                    Ally        
## 12 Norway                            1 Cobalt                       Ally        
## 13 Peru                              1 Tin                          Neutral     
## 14 Republic of Korea                 1 Indium                       Ally        
## 15 Russia                            1 Palladium                    Competitor  
## 16 South Africa                      4 Chromium, Platinum, Rare Ea… Neutral
write.csv(df4, file = "df4.csv", row.names = FALSE)