I: Abstract

As we enter the 3rd decade of the 21st century, the disastrous effects of climate change are becoming more and more apparent and at some point, will become irreversible. According to NASA, carbon dioxide levels are the highest they have been in 650,000 years and the global temperature has risen 2 degrees Fahrenheit since 1880. In addition, the polar ice sheets are losing 427 billion metric tons per year and sea level rises 3.3 millimeters per year. Scientists have reported that global temperatures could reach an irreversible tipping point by 2030 if drastic measures are not taken to slow down the rapidly occurring climate change. In addition to environmental impact assessment, mitigation strategies must be set into place in order to insure that future generations will continue to be able to live on a habitable planet.


II: Introduction

One way to minimize the amount of carbon released into the atmosphere is through the use of solar panels as a source of renewable energy. In this project, using a combination of data science methods and thorough research, I will propose a mitigation strategy that requires certain homeowners, based on the purchase price of their house, to install solar panels as a way of reducing carbon emissions. I will first use a dataset containing the annual number of metric tons of carbon emissions for certain cities in the United States. While it would be interesting to see the carbon emissions from every city in the U.S. this project will be on a smaller scale, only looking at prominent cities across the country. I will then look at more data containing median housing prices for these same specific cities. Exploring the data and using basic math will allow me to find the percentage change in carbon emissions per city as an indicator of how well my proposal will work. In the end, I would like to see the percentage change in carbon emissions per city if certain housing owners are required to install solar panels.


III: Data

The dataset that I will be using is from the CDP which is an international non-profit organization based in the United Kingdom, Germany, and the U.S. The main purpose of the company is to help companies and cities disclose the environmental impact of major corporations. The data came as a CSV file and has 187 observations for the 187 cities in the dataset. In addition, the data has 16 variables:

  • Account Number
  • City Name
  • Country
  • City Short Name
  • C40
  • Reporting Year
  • Measurement Year
  • Primary Methodology
  • Methodology Details
  • Total City-Wide Emissions in Metric Tons of CO2
  • Increase/Decrease From Last Year
  • Reason for Increase/Decrease
  • Current Population Year
  • Population
  • City Location
  • Country Location

The main variables that I will be looking at are the City Name, Country, Total City-Wide Emissions of CO2, Population, and City Location.


IV: Exploratory Data Analysis

IV.I: Emissions Data


I first wanted to see how many cities from each country reported their emissions for 2016. The graph below displays this statistic. It is clear that out of the 187 cities that reported their carbon emissions in 2016, the United States has the most cities in this dataset at 63 cities. Other notable countries with a significant number of cities include Brazil, Canada, Italy, and Portugal.



Doing a quick arrangement of the data allows me to see which cities within this 2016 dataset produced the most carbon emissions. Aside from New York City, it appears that the majority of these cities are located in Asia.


Top 5 Cities with Most CO2 Emissions
City Country Total City-Wide Emissions (metric tonnes CO2e)
Tokyo Japan 70,125,000
Incheon South Korea 69,794,140
Kaohsiung Taiwan 58,755,764
New York City USA 49,385,508
Seoul South Korea 47,612,664

After looking at the dataset a little more, I wanted to plot the location of all these cities on a map so I could see if there were any trends in terms of location for the cities that reported their emissions. However, I noticed that the city location variable in the dataset was one, long string containing both the longitude and latitude coordinate. Because of this, I was forced to split the column into two separate variables: Longitude and Latitude. After this, I removed the parenthesis from the columns so my data was ready to be plotted on a world map.



Once I plotted all the cities in the dataset, I moved on to the next step which was to isolate all the United States cities as these are the cities that I will be looking at when comparing them to housing data. Once I separated all 63 of the U.S. cities from the rest of them, I went ahead and plotted them on a map of the continental United States due to the fact that no cities in Alaska, Hawaii, or Puerto Rico were reported in the dataset.



I then wanted to see which cities in the United States were producing the most carbon emissions according to this 2016 dataset. From what I can tell, all these top 5 cities are high in population and are pretty industrial cities.


Top 5 U.S. Cities with Most CO2 Emissions
City Total City-Wide Emissions (metric tonnes CO2e)
New York City 49,385,508
Chicago 33,500,000
Houston 33,428,301
Las Vegas 29,657,130
Los Angeles 29,024,807

Next, I wanted to see which cities had the most emissions per capita in order to determine if there was a relationship between the amount of CO2 emissions and the population. This population portion of the dataset was taken from different years with the earliest being 2010 and the latest being 2016. As you can see in the chart below, the only city that remains from the top 5 from the previous chart is Las Vegas, Nevada.


Top 5 U.S. Cities with Most CO2 Emissions Per Capita
City Total City-Wide Emissions (metric tonnes CO2e) Current Population Year Current Population CO2 Tonnes Per Capita
Las Vegas 29,657,130 2,016 621,970 47.68257
Aspen and Pitkin County 394,341 2,010 8,427 46.79494
Brisbane, CA 148,025 2,015 4,603 32.15837
Cleveland 11,889,595 2,010 396,815 29.96256
St Louis 8,703,679 2,010 319,294 27.25914

IV.II: Housing Data

For the housing portion of the data, it would obviously be impossible to find a dataset with the exact sales price of each house in each city. For that reason, as an alternative, I will be using Zillow.com in order to gain a rough estimate of what the average price of housing in each city is. I will be using Zillow’s Home Value Index. According to Zillow’s website, this index value is seasonally adjusted and only includes the middle price tier of homes. I took the most recent value they had on the site which was updated September 30, 2020. I will create a new vector for house prices and add it to the dataframe.

Now, tet us look at the top 5 cities in this dataset with the highest and lowest average price for housing.

Top 5 Most Expensive Cities for Housing
City Total City-Wide Emissions (metric tonnes CO2e) Typical Housing Price
Los Altos Hills 57,243 4,398,248
Palo Alto 152,631 3,062,157
Piedmont, CA 43,442 2,237,911
Aspen and Pitkin County 394,341 2,113,927
Santa Monica 705,443 1,684,427
Top 5 Cheapest Cities for Housing
City Total City-Wide Emissions (metric tonnes CO2e) Typical Housing Price
Detroit 10,329,322 42,486
Alton, IL 401,079 67,303
Cleveland 11,889,595 73,686
St Louis 8,703,679 139,496
Baltimore 7,579,144 156,106

Next, I need to add in the total number of houses in each city. I will create another vector for housing count and add it to the dataframe. In the chart below, I will display the top 5 cities in the dataframe with the most houses. Disclaimer: all of the housing counts are taken from the United States Census Bureau under households from 2014-2018. It should be noted that these housing counts are rough estimates.


Top 5 Cities With Most Houses
City Total City-Wide Emissions (metric tonnes CO2e) Number of Households
New York City 49,385,508 3,154,103
Los Angeles 29,024,807 1,373,864
Chicago 33,500,000 1,056,118
Houston 33,428,301 848,340
Philadelphia 19,212,870 594,778

V: Analysis and Discussion

In order to perform any real analysis on this data and determine the magnitude of the effects of solar panels on carbon emissions, I first need to research the average price of solar panel installation. In addition, I will need to understand how much less CO2 emissions are produced when using a solar panel sysetm as opposed to using normal electricity. With this information I will be able to calculate the ratio of solar panel costs to housing price per city in order to determine in which cities it is financially feasible to enforce a solar panel installation requirement. The amount of CO2 emissions saved by using solar panels will allow me to simply calculate the percentage change per city in CO2 emissions if certain households are required to install these panels. In addition, I can calculate the change in carbon emissions in all 63 of these reported U.S. cities if everyone was required to install solar panels.

According to Energy Sage, the average price for a 6 kilowatt solar panel system is $13,124 in the United States in 2020 after tax credits are taken from the original average price of $17,760. For this project, I have made the assumption that everyone will install a 6kW solar panel system due to the fact that it is the most frequently installed system according to the research I have done.

Now that I have the average price for a 6kW solar panel system, I will calculate the relationship between solar panel price and housing price per city as a percentage. This will give me an idea of what is affordable in each city based on the typical housing price. This percentage will be added to the dataframe as a new column.

Cost of 6kW Solar System as % of Typical Housing Price
City Typical Housing Price Solar Panel Cost as % of House Price
Lake Forest, IL 753,653 1.741385
Alton, IL 67,303 19.499874
Eugene 354,073 3.706580
Portland, OR 479,166 2.738926
Brisbane, CA 1,050,747 1.249016

The chart above is shown to give an idea of the cost of a solar panel system in relation to the cost of housing in each city. For example, the typical house in Brisbane, California costs $1,050,747. The average cost of a 6kw solar panel system is about 1.24% of the housing price.


Finding the amount of CO2 emissions prevented per solar panel system is a little more difficult to determine due to a number of factors. Firstly, it is difficult to estimate the production of solar panel system due to the fact that production can vary wildly based on location and placement. For example, places such as Seattle that obviously do not get a lot of constant sunlight will have less production from their solar panels than states such as Arizona or Nevada where there are deserts and lots of sunlight throughout the majority of the year. In addition, solar panel production depends on placement factors such as the angle or which side of the roof on which it is placed.

For these reasons, I will be using a VERY rough estimate taken from Solar Reviews. According to their website, a 6kW solar panel system can produce between 6351kWh and 10,074kWh per year in optimal conditions. With all the varying factors that affect solar panels in mind, I am going to use the lower end of this spectrum as an estimate to how much a 6kW solar panel system produces during the course of one year.

Estimate: 6351kWh per year

The next issue I run into is converting this production number into an measure of how much CO2 is emitted into the atmosphere. The problem with this is that each state has different regulation laws which changes the amount of CO2 created by electricity production. I will be taking 2018 data from the U.S. Energy Information Administration (EIA) in order to determine how many pounds of carbon dioxide were released into the atmosphere for every 1 kWh of standard electricity produced. I will create a vector for these conversion rates and add it to the dataframe based on the state each city is in.


Pounds of CO2 Emitted per kWh Produced
City Conversion Rate (lbs CO2/kWh)
Lake Forest, IL 0.846
Alton, IL 0.846
Eugene 0.302
Portland, OR 0.302
Brisbane, CA 0.491

The chart above is a quick sample of some of the conversion rates for the first five cities in the dataset.

As a side note, I would like to quickly point out that when inputting the conversion rates, I noticed that Vermont had the lowest conversion rate at 0.010 pounds of CO2 per kWh of electricity produced. I dug a little deeper and found that, “In 2019, Vermont generated 99.9% of its electricity from renewable resources, a larger share than in any other state.”

I will now multiply these conversion rates by my estimate of how much electricity is produced in one year by a 6kW solar panel system. Then, I will multiply this number by the number of houses per city. This result will give me the total amount of CO2 in pounds reduced if every house in the city implemented a 6kW solar panel system.

\[ CO2 Saved (pounds) = 6351 kWh \cdot Conversion Rate \cdot Number of Houses \]

I then have to convert this number from pounds to metric tons in order to compare it to the total city-wide emissions from 2016.

\[ CO2Saved(Metric Tons) = CO2Saved(pounds) / 2204.6 \]
CO2 Saved if Every House Has 6kW Solar System
City CO2 Saved (metric tons)
Lake Forest, IL 16,762.73
Alton, IL 28,007.75
Eugene 59,903.85
Portland, OR 230,052.36
Brisbane, CA 2,575.75

Chart above, containing the first five cities in the dataset, is given as an example for how much less carbon emissions are emitted in one year if every house in each city were to install a 6kW solar panel system.


Now that I have the amount of CO2 saved per year per city, I would like to calculate the percent change that would occur in the total city-wide emissions if every housing owner were to install this solar panel system.

Percent Decrease in CO2 Emissions
City Percent Decrease
Lake Forest, IL 4.1660620
Alton, IL 6.9831017
Eugene 4.7923080
Portland, OR 3.2984574
Brisbane, CA 1.7400778
Roanoke 4.7416022
Austin 8.2480218
Durham 6.3894509
San Antonio 9.6606791
Emeryville, CA 5.4444217
Hayward 6.4428487
Davis, CA 9.9876627
Iowa 7.9062632
Indianapolis 79.3800986
Aspen and Pitkin County 3.1018039
Hermosa Beach, CA 10.0311410
Columbus 12.5845538
Burlington 0.1151009
Flagstaff 5.1589139
Dallas 8.9648058
Houston 7.7495024
Boulder 9.8376686
Abington 7.6801964
Albany 4.5256216
Arlington, VA 9.3878990
Yonkers 8.0125318
Denver 13.0728473
Atlanta 5.9412601
Knoxville 4.5278452
Baltimore 8.1202984
San Diego 5.6410061
Benicia 2.2858888
Blacksburg 7.7867179
Detroit 8.4746930
Boston 10.2162840
Chicago 7.6833446
Cleveland 5.5850497
District of Columbia 13.0346451
Lakewood 15.1139474
Lancaster, PA 13.7098633
Las Vegas 1.7087281
Los Altos Hills 7.5439399
Los Angeles 6.6952717
University City, MO 15.0890946
Minneapolis 11.1390176
Nashville and Davidson 4.9696023
New Orleans 10.6493416
New York City 8.5370266
Oakland 8.3555584
Palo Alto 24.2913254
Savannah 3.9604713
Philadelphia 7.0185871
Piedmont, CA 12.8546760
West Hollywood 5.7086861
St Louis 7.8891186
Pittsburgh 6.4325991
Reno 4.9857343
Richmond, VA 6.3383109
San Francisco 9.4532948
Santa Monica 9.1205109
Seattle 3.5865202
Somerville, MA 13.0420675
Tucson 8.3813849

Just to reiterate, the chart above shows the percentage decrease in CO2 emissions from 2016 if every home in each city were required to install a 6kW solar panel system.

One thing that I noticed as an outlier was Indianapolis who had a 79% decrease in carbon emissions. At first, I thought my numbers were off so I checked my math. However, it turns out that in 2018 in Indiana, for every kWh of electricity produced, 1.775 pounds of CO2 were released, which is significantly higher than most cities. When you take away all that CO2 by implementing solar panels, the percent decrease would therefore be higher than normal.


Getting to my next step, I want to calculate the percentage decrease for all 63 of these cities combined.

Percent Decrease in CO2 Emissions For All 63 Reported Cities
Total Emissions 2016 Total Emissions with Solar Panel Plan Total CO2 Saved Percent Decrease
431,948,409 398,189,422 33,758,987 7.815514

If all 63 cities had every house install a 6kW solar panel system, the total number of CO2 emissions would decrease by 7.8%.


Now, finally I can get to the main proposal of this project.
Proposal: If the cost of a 6kW solar panel system is less than 3% of the total price of the house, the homeowner is required to install this solar panel system as a way to mitigate the effects of climate change by reducing the amount of carbon emissions released in the atmosphere.

The first mitigation strategy with everyone in each city having a solar panel system obviously would not work due to the fact that not everyone can afford a 6kW solar panel system. For that reason, I came to the conclusion that only certain homeowners should be required to install solar panels based on the cost of their house. I chose 3% due to the fact that it is relatively financially feasible for these homeowners. Since the cost of a 6kW solar panel system is on average $13,124, the lowest price of a house that would make the cost of the solar panel system 3% is $437,466.67. Any housing price lower than that would make the cost of the solar panel system greater than 3% of the price of the house.

I then filtered out all the cities that have the cost of the solar panel system as higher than 3% of the price of the typical house. This allowed me to find the percentage change in CO2 emissions if all housing owners with a housing price greater than $437,466.67 are required to install a 6kW solar panel system.


After filtering the dataset, it is clear that 28 cities have the price of a 6kW solar panel system greater than 3% of the cost of the typical house in that city. That leaves 35 cities with typical housing being less than $437,466.67.

Percent Decrease in CO2 Emissions With Proposal in Place
Total Emissions 2016 Total Emissions with 3% Solar Panel Plan Total CO2 Saved Percent Decrease
431,948,409 420,014,858 11,933,551 2.762726

As visible in the chart above, when this specific group of homeowners are required to install a solar panel system, almost 12 million metric tons of CO2 per year across these 63 cities are saved. This is almost a 3% decrease in the amount of carbon emissions when comparing it to the total amount of CO2 produced by these cities in 2016.


VI: Conclusion

Before I get into the conclusion for this project, I would like to insert a disclaimer here, saying that I understand that this project idea and concept is completely theoretical and based on a lot of assumptions. Firstly, the data is based on 63 U.S. cities, which is a very small sample size. The emissions data was from 2016, which was 4 years ago. The housing data was all very rough estimates taken from Zillow along with the U.S. Census Bureau. I made the assumption for the solar panel system price based on a 2020 U.S. estimate. I also made the assumption that everyone will install a 6kW solar panel system due to the fact that it is the most frequently installed system. In addition, it was difficult to come up with an estimate for the production numbers for solar panels due to the fact each solar panel system produces different amounts based on its location and position. I am still not sure if I estimated too high or too low with 6351kWh per year. Going back to the housing prices, I made the assumption that the typical housing price based on the Zillow House Index was the price for all the houses in that specific city. For example, if the price index said the typical home in San Francisco cost $1.4 million, I assumed that all 300,000 of these houses had that price, which is obviously an incorrect way of thinking. Generalizing the price of homes for the entire city made the data simpler to work with. Lastly, I did not take into account industrial buildings, business, or apartments who have multiple families living in one building. Once again, I understand that this project is not completely realistic, but it was created to give me an idea of the environmental benefits of solar panel systems.

To conclude, my proposal was that if the cost of a 6kW solar panel system ($13,124) was less than 3% of the purchase price of the house, these homeowners were required to install this solar panel system. This 3% number was determine based on my opinion that if a person owns a house worth more than $437,466.67, they should be financially able to purchase a 6kW solar panel system as a way to slow the effects of climate change. When this 3% plan was imposed on the 63 cities in the dataset, only 28 of those cities were required to install solar panels. This resulted in a 2.76% decrease in carbon emissions when compared to the emissions data from 2016 for those 63 cities. On a more general level, disregarding the price of their houses and forcing all homeowners to install solar panel systems decreased carbon emissions by 7.82% which is significant enough to have a positive effect on our environment. As stated above, I am not sure if my estimation for the average production of a 6kW solar panel system is accurate but I chose the lower end of the estimate so as to not overpredict the benefits of the panels. If I were to increase the average production of the panels, the total amount of carbon emissions in 2016 would decrease drastically. With that being said, more mitigation strategies need to be created in order that we stop the effects of climate change before they become irreversible. Time is running out and drastic measures need to be taken soon whether they be in the form of solar panels or other mitigation strategies.


VIII: Appendix

library(tidyverse)
library(sf)
library(readr)
library(USAboundaries)
library(USAboundariesData)
library(rnaturalearth)
library(rnaturalearthdata)
library(scales)
emissions <- read_csv("~/github/Solar-Panel-Proposal/data/2016_-_Citywide_Emissions__Map.csv")

emissions = emissions %>% 
  separate(`City Location`, c('Lat', 'Long'), sep = ",")

emissions$Lat <- substring(emissions$Lat, 2)
emissions$Long <- substr(emissions$Long, 1, nchar(emissions$Long)-1)

emissions$Lat = as.numeric(emissions$Lat)
emissions$Long = as.numeric(emissions$Long)

no_cities = emissions %>% 
  group_by(Country) %>% 
  summarise(Number_of_Cities = n())
ggplot(data = no_cities, aes(x = Country, y= Number_of_Cities), las=2) +
  geom_bar(stat="identity") +
  theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) +
  labs(x = 'Country',
       y = 'Number of Cities',
       title = 'Total Number of Cities that Reported Their Annual Emissions in 2016',
       caption = 'Based on CDP Dataset')
top5 = emissions %>% 
  select(`City Short Name`, Country, `Total City-wide Emissions (metric tonnes CO2e)`) %>% 
  arrange(-`Total City-wide Emissions (metric tonnes CO2e)`) %>% 
  head(5)

knitr::kable(top5, caption = "Top 5 Cities with Most CO2 Emissions", col.names = c("City","Country","Total City-Wide Emissions (metric tonnes CO2e)"), "simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
hos_sf = st_as_sf(emissions, coords = c("Long", "Lat"), crs = 4326)

world = ne_countries(scale = 'medium', returnclass = 'sf') %>% 
  st_transform(4326)

ggplot(data = world) +
  geom_sf() +
  geom_sf(data = hos_sf, color = "red") +
  labs(title = "Cities That Disclosed Their City-Wide Emissions in 2016",
       x = "Longitude",
       y = "Latitude",
       caption = "Taken from 2016 Citywide Emissions Dataset")
USA = USAboundaries::us_states() %>% 
  st_transform(4326) %>% 
  filter(name != 'Alaska' & name != 'Puerto Rico' & name != 'Hawaii')

counties = USAboundaries::us_counties() %>% 
  st_transform(4326) %>% 
  filter(state_name != 'Alaska' & state_name != 'Puerto Rico' & state_name != 'Hawaii')

us_emissions <- hos_sf %>% 
  filter(Country == 'USA')

ggplot() +
  geom_sf(data = USA, color = "blue") +
  geom_sf(data = us_emissions, color = "red") +
  coord_sf(datum = st_crs(us_emissions)) +
  labs(title = "U.S. Cities That Disclosed Their City-Wide Emissions in 2016",
       caption = "Taken from 2016 Citywide Emissions Dataset")
top5US = emissions %>% 
  filter(Country == 'USA') %>% 
  select(`City Short Name`, `Total City-wide Emissions (metric tonnes CO2e)`) %>% 
  arrange(-`Total City-wide Emissions (metric tonnes CO2e)`) %>% 
  head(5)
  

knitr::kable(top5US, caption = "Top 5 U.S. Cities with Most CO2 Emissions", col.names = c("City","Total City-Wide Emissions (metric tonnes CO2e)"), "simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
USAemissions = emissions %>% 
  filter(Country == 'USA')

top5percapita = USAemissions %>% 
  mutate(Per_Capita = `Total City-wide Emissions (metric tonnes CO2e)` / `Current Population`) %>% 
  select(`City Short Name`, `Total City-wide Emissions (metric tonnes CO2e)`, `Current Population Year`, `Current Population`, Per_Capita) %>% 
  arrange(-Per_Capita) %>% 
  head(5)
  
knitr::kable(top5percapita, caption = "Top 5 U.S. Cities with Most CO2 Emissions Per Capita", col.names = c("City","Total City-Wide Emissions (metric tonnes CO2e)", "Current Population Year", "Current Population", "CO2 Tonnes Per Capita"), "simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
prices <- c(753653, 67303, 354073, 479166, 1050747, 177683, 426750, 264923, 198162, 594405, 702173, 709630, 233312, 165692, 2113927, 711361, 180611, 357731, 400251, 238156, 196902, 770097, 259906, 189889, 754942, 549387, 466601, 296590, 213420, 156106, 675496, 656990, 274122, 42486, 659598, 278816, 73686, 641121, 457166, 259906, 296251, 4398248, 768046, 198764, 301333, 298039, 240091, 632271, 804577, 3062157, 190654, 200306, 2237911, 906839, 139496, 190589, 409375, 249656, 1405199, 1684427, 773508, 731656, 219800)

USAemissions$Price <- prices

top5price = USAemissions %>% 
  select(`City Short Name`, `Total City-wide Emissions (metric tonnes CO2e)`, Price) %>% 
  arrange(-Price) %>% 
  head(5)
bot5price = USAemissions %>% 
  select(`City Short Name`, `Total City-wide Emissions (metric tonnes CO2e)`, Price) %>% 
  arrange(Price) %>% 
  head(5)

knitr::kable(top5price, caption = "Top 5 Most Expensive Cities for Housing", col.names = c("City","Total City-Wide Emissions (metric tonnes CO2e)", "Typical Housing Price"),"simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
knitr::kable(bot5price, caption = "Top 5 Cheapest Cities for Housing", col.names = c("City","Total City-Wide Emissions (metric tonnes CO2e)", "Typical Housing Price"),"simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
housecount <- c(6878, 11492, 68855, 264428, 1821, 42037, 370043, 123444, 497794, 6456, 47768, 24597, 29975, 335373, 3079, 8979, 352543, 16197, 23610, 505816, 848340, 42643, 20841, 41207, 104716, 74848, 294258, 199478, 79579, 238436, 503463, 11130, 13436, 260383, 266247, 1056118, 169365, 281322, 65737, 22118, 226396, 3053, 1373864, 15468, 173916, 268061, 154036, 3154103, 161483, 26212, 53187, 594778, 3948, 23538, 140455, 136275, 98844, 89846, 359673, 45487, 323446, 32851, 210816)

USAemissions$Num_Houses <- housecount

top5count = USAemissions %>% 
  select(`City Short Name`, `Total City-wide Emissions (metric tonnes CO2e)`, Num_Houses) %>% 
  arrange(-Num_Houses) %>% 
  head(5)

knitr::kable(top5count, caption = "Top 5 Cities With Most Houses", col.names = c("City","Total City-Wide Emissions (metric tonnes CO2e)", "Number of Households"),"simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
USAemissions = USAemissions %>% 
  mutate(percent_of_price = (13124 / Price) * 100)

percentprice = USAemissions %>% 
  select(`City Short Name`, Price, percent_of_price) %>% 
  head(5)

knitr::kable(percentprice, caption = "Cost of 6kW Solar System as % of Typical Housing Price", col.names = c("City","Typical Housing Price", "Solar Panel Cost as % of House Price"),"simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
convertrate = c(0.846, 0.846, 0.302, 0.302, 0.491, 0.772, 1.060, 0.814, 1.060, 0.491, 0.491, 0.491, 1.189, 1.775, 1.379, 0.491, 1.361, 0.010, 0.919, 1.060, 1.060, 1.379, 0.787, 0.464, 0.772, 0.464, 1.379, 0.933, 0.790, 0.896, 0.491, 0.491, 0.772, 1.167, 0.808, 0.846, 1.361, 1.188, 1.379, 0.787, 0.777, 0.491, 0.491, 1.697, 1.066, 0.790, 1.094, 0.464, 0.491, 0.491, 0.933, 0.787, 0.491, 0.491, 1.697, 0.787, 0.777, 0.772, 0.491, 0.491, 0.201, 0.808, 0.919)

USAemissions$conversion_rate = convertrate

conversionrate = USAemissions %>% 
  select(`City Short Name`, conversion_rate) %>% 
  head(5)

knitr::kable(conversionrate, caption = "Pounds of CO2 Emitted per kWh Produced", col.names = c("City", "Conversion Rate (lbs CO2/kWh)"),"simple")
USAemissions = USAemissions %>% 
  mutate(CO2_saved_lbs = 6351 * conversion_rate * Num_Houses)

USAemissions = USAemissions %>% 
  mutate(CO2_saved_tons = CO2_saved_lbs / 2204.6)

amountsaved = USAemissions %>% 
  select(`City Short Name`, CO2_saved_tons) %>% 
  head(5)

knitr::kable(amountsaved, caption = "CO2 Saved if Every House Has 6kW Solar System", col.names = c("City", "CO2 Saved (metric tons)"),"simple", format.args = list(big.mark = ",", 
  scientific = FALSE))
USAemissions = USAemissions %>% 
  mutate(percentchange = ((`Total City-wide Emissions (metric tonnes CO2e)` - (`Total City-wide Emissions (metric tonnes CO2e)` - CO2_saved_tons)) / `Total City-wide Emissions (metric tonnes CO2e)`) * 100)

percentdec = USAemissions %>% 
  select(`City Short Name`, percentchange) 

knitr::kable(percentdec, caption = "Percent Decrease in CO2 Emissions", col.names = c("City", "Percent Decrease"),"simple")
final = data.frame("Total City-Wide Emissions" = 431948409, "Total City-Wide Emissions w Panels" = 398189422, "Total CO2 Saved" = 33758987)

final1 = final %>% 
  mutate(percentchanger = (Total.CO2.Saved / Total.City.Wide.Emissions) * 100)
final2 = final %>% 
  mutate(Emissions_with = Total.City.Wide.Emissions - Total.CO2.Saved) %>% 
  select(Total.City.Wide.Emissions, Emissions_with)

knitr::kable(final1, caption = "Percent Decrease in CO2 Emissions For All 63 Reported Cities", col.names = c("Total Emissions 2016", "Total Emissions with Solar Panel Plan", "Total CO2 Saved", "Percent Decrease"), "simple", format.args = list(big.mark = ",", scientific = FALSE))
counts <- c(final2$Total.City.Wide.Emissions, final2$Emissions_with)
barplot(counts, main="CO2 Emissions With and Without Solar Panel Plan",
  xlab="CO2 Emissions (metric tons)", col=c("darkblue","red"), names.arg= c("2016 Total Emissions in 63 Cities", "Total Emissions with Solar Panel Plan"))
filteredUSemissions = USAemissions %>% 
  filter(percent_of_price < 3)
proposal = data.frame("Total City-Wide Emissions" = 431948409, "Total City-Wide Emissions w Panels" = 420014858, "Total CO2 Saved" = 11933551)

proposal1 = proposal %>% 
  mutate(percentchange1 = (Total.CO2.Saved / Total.City.Wide.Emissions) * 100)
proposal2 = proposal %>% 
  mutate(Emissions_with = Total.City.Wide.Emissions - Total.CO2.Saved) %>% 
  select(Total.City.Wide.Emissions, Emissions_with)

knitr::kable(proposal1, caption = "Percent Decrease in CO2 Emissions With Proposal in Place", col.names = c("Total Emissions 2016", "Total Emissions with 3% Solar Panel Plan", "Total CO2 Saved", "Percent Decrease"), "simple", format.args = list(big.mark = ",", scientific = FALSE))
counts1 <- c(proposal2$Total.City.Wide.Emissions, proposal2$Emissions_with)
barplot(counts1, main="CO2 Emissions With and Without 3% Solar Panel Proposal",
  xlab="CO2 Emissions (metric tons)", col=c("darkblue","red"), names.arg= c("2016 Total Emissions in 63 Cities", "Emissions with 3% Solar Panel Plan"))

library(icon)
fa("globe", size = 5, color="green")