# Reading the csv file
dataset <- read.csv("plastic - Sheet1 (1).csv")
# installing packages needed
install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
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
# Mutating data to get total number of plastics produces and getting ratio
dataset <- dataset %>%
  mutate(Total.Plastic.Produced = `TOTAL.LBS.OF.PCR.PLASTIC` + `TOTAL.LBS.OF.VIRGIN.PLASTIC`)

dataset <- dataset %>%
  mutate(Total.Plastic.over.networth = `Total.Plastic.Produced`/`COMPANY.NET.WORTH.IN.BILLIONS`)
# Making a bar graph to compare the ratio of each company
library("ggplot2")
ggplot(dataset, aes(x = reorder(COMPANY, -Total.Plastic.over.networth), y = Total.Plastic.over.networth, fill = COMPANY)) +
  geom_bar(stat = "identity") +
  labs(title = "Plastic produced by each company for 2023",
       x = "Company",
       y = "Plastic produced") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 5),
          legend.text = element_text(size = 5),  
        legend.title = element_text(size = 3),
        legend.key.size = unit(0.5, "lines")
  )

# We realize that SVC Manfucaturing has way toohigh of a ratio. Out of the different food and beverage industries, SVC Manufacturing has the highest plastic produced for packaging in relation the company's networth for the year 2023.
# We still want to have a better visual of how much plastic each company produced for the year so for now, we will remove SVC Manufacturing the removing that row.
# Removing SVC Manufacturing
dataset2 <- dataset [-10,]
  
# Making another bar graph without SVC Manufacturing
library("ggplot2")
ggplot(dataset2, aes(x = reorder(COMPANY, -Total.Plastic.over.networth), y = Total.Plastic.over.networth, fill = COMPANY)) +
  geom_bar(stat = "identity") +
  labs(title = "Plastic produced by each company except SVC Manufacturing for 2023",
       x = "Company",
       y = "Plastic produced") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 5),
        legend.text = element_text(size = 5),  
        legend.title = element_text(size = 3),
        legend.key.size = unit(0.5, "lines")
  )

dataset3 <- dataset %>%
  mutate(Percentage = (`Total.Plastic.over.networth`/881848000000)*100)

dataset3
##                                 COMPANY TOTAL.LBS.OF.PCR.PLASTIC
## 1                  Niagara Bottling LLC                 37259672
## 2                       C.G. Roxane LLC                 15895124
## 3          Reyes Coca-Cola Bottling LLC                 15468783
## 4                   Swire Coca-Cola USA                 15468783
## 5                 The Coca-Cola Company                 15468783
## 6             Pepsi Cola Bottling Group                 12483849
## 7                     HPP Food Services                 10102942
## 8               BlueTriton Brands, Inc.                  7227332
## 9     North American Coffee Partnership                  6967208
## 10                    SVC Manufacturing                  5943416
## 11        The American Bottling Company                  4870184
## 12                    Fiji Water Co LLC                  2199651
## 13 Tropicana Manufacturing Company, Inc                  1866570
## 14                            Motts Inc                  1811385
## 15                       Nestle USA Inc                  1639787
## 16                   Premium Waters Inc                  1601420
## 17                     Pepsi Lipton Tea                  1395468
## 18                 Danone North America                  1283816
##    TOTAL.LBS.OF.VIRGIN.PLASTIC YEAR COMPANY.NET.WORTH.IN.BILLIONS
## 1                    103914554 2023                      28.00000
## 2                     23623781 2023                       0.05630
## 3                     64420662 2023                      19.90000
## 4                     64420662 2023                       3.00000
## 5                     64420662 2023                     309.59000
## 6                     16671176 2023                     214.53000
## 7                      3429232 2023                       0.01410
## 8                     18930432 2023                       4.70000
## 9                       200579 2023                       1.50000
## 10                    38510946 2023                       0.00766
## 11                    15360053 2023                       1.72700
## 12                     5612681 2023                       0.05000
## 13                     2864574 2023                       1.10000
## 14                     4356468 2023                       0.04320
## 15                     7609226 2023                     256.18000
## 16                     7369267 2023                       0.21000
## 17                     6636067 2023                       9.57000
## 18                     2680223 2023                      42.96000
##    Total.Plastic.Produced Total.Plastic.over.networth   Percentage
## 1               141174226                5.041937e+06 5.717467e-04
## 2                39518905                7.019344e+08 7.959811e-02
## 3                79889445                4.014545e+06 4.552423e-04
## 4                79889445                2.662982e+07 3.019774e-03
## 5                79889445                2.580492e+05 2.926232e-05
## 6                29155025                1.359019e+05 1.541103e-05
## 7                13532174                9.597287e+08 1.088315e-01
## 8                26157764                5.565482e+06 6.311158e-04
## 9                 7167787                4.778525e+06 5.418762e-04
## 10               44454362                5.803442e+09 6.581000e-01
## 11               20230237                1.171409e+07 1.328357e-03
## 12                7812332                1.562466e+08 1.771809e-02
## 13                4731144                4.301040e+06 4.877303e-04
## 14                6167853                1.427744e+08 1.619036e-02
## 15                9249013                3.610357e+04 4.094081e-06
## 16                8970687                4.271756e+07 4.844095e-03
## 17                8031535                8.392409e+05 9.516843e-05
## 18                3964039                9.227279e+04 1.046357e-05
ggplot(dataset3, aes(x = reorder(COMPANY, -Percentage), y = Percentage, fill = COMPANY)) +
  geom_bar(stat = "identity") +
  labs(title = "Plastic produced by each company",
       x = "Company",
       y = "Plastic produced") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 5),
        legend.text = element_text(size = 5),  
        legend.title = element_text(size = 3),
        legend.key.size = unit(0.5, "lines")
  )