URL: http://rpubs.com/PasquesD/frfr
library(fueleconomy)
library(tidyverse)
library(ggthemes)
vehicles <- vehicles
vehicles$ranges <- ifelse(vehicles$year <= 1989, "1984-1989", ifelse((vehicles$year > 1989) & (vehicles$year <= 1994), "1990-1994", ifelse((vehicles$year > 1995) & (vehicles$year <= 1999), "1995-1999", ifelse((vehicles$year > 2000) & (vehicles$year <= 2004), "2000-2004", ifelse((vehicles$year > 2005) & (vehicles$year <= 2009), "2005-2009", "2010-2014")))))
vehicles$ctyFT <- ave(vehicles$cty, vehicles$fuel, vehicles$ranges)
vehicles$hwyFT <- ave(vehicles$hwy, vehicles$fuel, vehicles$ranges)
fuel_plot <- ggplot(vehicles, aes(x = reorder(fuel, cty)))+
geom_linerange(aes(ymin = ctyFT, ymax = hwyFT), color = "blue", size = 2)+
coord_flip()+
facet_wrap(~ranges, scales = "free_y", nrow = 3)+
theme_calc()+
labs(title = "The Change in Fuel Type and Fuel Efficiency\n over the Past 30 Years", subtitle = "1984-2014", x = "Fuel type", y = "Miles per Gallon")+
theme(panel.background = element_rect(fill = "gray94"))+
geom_point(aes(y = hwyFT, color = "Average\nHighway\nMPG"), shape = 18, size = 1.5)+
geom_point(aes(y = ctyFT, color = "Average\nCity\nMPG"), shape = 18, size = 1.5)+
theme(legend.position = "right",
legend.title = element_blank(),
legend.key.size = unit(3, 'lines'))
fuel_plot
The dataset used to produce the above figures is from fueleconomy package within RStudio provided by the EPA. The dataset includes information regarding cars from 1984-2014 regarding their model type, engine displacement, and miles per gallon among many other things. With the data in hand, we sought to find a relationship between fuel type and miles per gallon. Something we did expect our figures to reflect was the innovation of different fuel types and when they hit the general market. Our hypothesis was that the fuel efficiency (miles per gallon) would increase over time, which lead us to our research question; how did the miles per gallon average change over time with regards to different fuel types?
To pursue this question the decision was made to focus on the city miles per gallon and highway miles per gallon because the values would be significantly different. Our findings show that the number of different fuel types changed a lot over the course of 30 years having there been only three fuel types in 1984 and twelve different fuel types in 2014. The figures show that electricity powered cars have by far the highest miles per gallon. Also an interesting finding about electric cars is that their city miles per gallon is actually better than their highway miles per gallon. The rest of the fuel types have better fuel efficiency on the highway rather than in a city. Another interesting point is that diesel fuel from 2000-2004 was at its most efficient. Overall, our hypothesis that fuel efficiency would increase over time was true, but the ways that fuel efficiency changed and the type of fuels that contributed to the increase in fuel efficiency made our figure informative.