#INTRODUCTION: As a life long driver of gasoline powered vehicles, and someone who rightfully believes that so called “renewable” energies are not ready to replace fossil fuel sources, yet. What most people tend to forget or ignore is that most electric energy is still produced by burning fossil fuels. The cost of of reliable gasoline is on utmost importance not just for me on an individual level but for society as a whole. There is good reason why emerging economies like china, are not participating in the green new deal like endeavors, and are instead utilizing cheaper, more reliable, and much more efficient fossil fuels sources. In this analysis I will explore the relationship of gas prices in NYS cities and townships.
To call in the libraries.
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v ggplot2 3.3.6 v purrr 1.0.1
## v tibble 3.1.8 v dplyr 1.0.10
## v tidyr 1.3.0 v stringr 1.5.0
## v readr 2.1.2 v forcats 0.5.2
## Warning: package 'ggplot2' was built under R version 4.1.3
## Warning: package 'tibble' was built under R version 4.1.3
## Warning: package 'tidyr' was built under R version 4.1.3
## Warning: package 'readr' was built under R version 4.1.3
## Warning: package 'purrr' was built under R version 4.1.3
## Warning: package 'dplyr' was built under R version 4.1.3
## Warning: package 'stringr' was built under R version 4.1.3
## Warning: package 'forcats' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.1.3
##
## Attaching package: 'lubridate'
##
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
gas_prices <- read_csv("Gasoline_Retail_Prices_Data.csv")
## Rows: 800 Columns: 18
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (1): Date
## dbl (17): New York State Average ($/gal), Albany Average ($/gal), Batavia Av...
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
To clean up and tidy the data by pivoting longer, switching the way the data and variable variables are presented.
monthly_avg_gas_price <- gas_prices %>%
pivot_longer(
-Date,
names_to = "Location",
values_to = "Average Price - Dollars Per Gallon"
) %>%
mutate(
Location = str_remove(Location, " Average \\(\\$\\/gal\\)"),
Date = mdy(Date),
Year = year(Date),
Month = month(Date),
year_month = str_c(Year,Month, "1", sep = "-") %>%
ymd()
) %>%
group_by(Location, year_month) %>%
summarise(mnthly_avg_price = mean(`Average Price - Dollars Per Gallon`), .groups = "drop")
To add visualization plot.
city_prices <- monthly_avg_gas_price %>%
filter(!Location %in% "New York State")
state_prices <- monthly_avg_gas_price %>%
filter(Location %in% "New York State")
ggplot() +
geom_line(
data = city_prices,
aes(x = year_month, y = mnthly_avg_price, color = Location, group = Location)
) +
geom_line(
data = state_prices,
aes(x = year_month, y = mnthly_avg_price),
color = "black"
)
## Warning: Removed 882 row(s) containing missing values (geom_path).
#CONCLUSION To conclude I could not find a relationship between price and location. The price seems to move up and down in concert within the entire NYS. In my opinion electric vehicles look cool and have lots of cool gadgets. Personally I cannot wait unit technology and innovation creates a viable alternative to gasoline powered cars that the average american can afford.