Last active
August 29, 2015 14:05
-
-
Save ateucher/d50981c611d51dd2783e to your computer and use it in GitHub Desktop.
Compare fuel economy of cars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fueleconomy) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
comp_vehicles <- vehicles %>% | |
filter(cyl == 4, | |
grepl("Utility", class), | |
make %in% c("Honda", "Toyota","Subaru", | |
"Hyundai", "Kia", "Mazda", | |
"Mitsubishi", "Nissan"), | |
year > 2007, | |
year < 2014, | |
grepl("All-Wheel|4-Wheel", drive)) %>% | |
mutate(transmission = ifelse(grepl("Auto", trans), "Automatic", "Manual") | |
) %>% | |
gather(mpg_type, mpg, cty, hwy) | |
ggplot(comp_vehicles, aes(x = mpg, y = reorder(paste(make, model), mpg, max), | |
colour = transmission)) + | |
facet_grid(mpg_type ~ year, scales = "free_y") + | |
geom_point(aes(size = displ)) + scale_size(range = c(2,4)) + | |
labs(x = "Miles Per Gallon", y = "Make / Model", size = "Engine displacement", | |
colour = "Transmission") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment