Created
August 1, 2014 00:53
-
-
Save stedy/a198bb0c7b010dcdf7af to your computer and use it in GitHub Desktop.
Gas efficiency analysis
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
Date | Brand | Mileage | Cost | Grade | Amount | TotalCost | |
---|---|---|---|---|---|---|---|
1/3/2014 | 76 | 43159 | 3.499 | 87 | 4.985 | 17.44 | |
1/13/2014 | Arco | 43415 | 3.29 | 87 | 9.205 | 30.28 | |
1/18/2014 | Shell | 43655 | 3.499 | 87 | 9.521 | 33.31 | |
1/22/2014 | Costco | 43938 | 3.179 | 87 | 9.28 | 29.5 | |
1/28/2014 | 76 | 44201 | 3.499 | 87 | 9.263 | 32.41 | |
2/15/2014 | 76 | 44434 | 3.499 | 87 | 9.434 | 33.01 | |
3/5/2014 | Shell | 44664 | 3.699 | 87 | 9.801 | 36.25 | |
3/16/2014 | 76 | 44917 | 3.519 | 87 | 9.014 | 31.72 | |
3/21/2014 | 7-11 (Citgo) | 45179 | 3.699 | 87 | 9.014 | 33.34 | |
3/26/2014 | Arco | 45471 | 3.639 | 87 | 9.656 | 35.14 | |
3/31/2014 | Arco | 45770 | 3.679 | 87 | 9.463 | 34.81 | |
4/12/2014 | 76 | 45995 | 3.959 | 87 | 8.88 | 35.16 | |
4/27/2014 | 76 | 46208 | 4.099 | 87 | 8.671 | 35.54 | |
5/17/2014 | 76 | 46475 | 3.999 | 87 | 9.101 | 36.39 | |
5/25/2014 | Safeway | 46735 | 3.819 | 87 | 9.037 | 34.51 | |
5/31/2014 | Shell | 47035 | 4.05 | 87 | 9.326 | 37.77 | |
6/15/2014 | 76 | 47270 | 4.059 | 87 | 8.292 | 33.66 | |
7/4/2014 | Safeway | 47531 | 3.959 | 87 | 9.12 | 36.11 | |
7/6/2014 | Safeway | 47843 | 4.119 | 87 | 8.796 | 36.23 | |
7/18/2014 | Shell | 48130 | 3.939 | 87 | 8.967 | 35.32 | |
7/19/2014 | Chevron | 48449 | 3.999 | 87 | 9.166 | 36.65 | |
7/27/2014 | Shell | 48743 | 4.099 | 87 | 8.572 | 35.14 |
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(plyr) | |
library(ggplot2) | |
raw <- read.csv("gas2014.csv") | |
avediff <- diff(raw$Mileage) | |
raw$totalmiles <- c(NA, avediff) | |
raw$Avgcost <- raw$totalmiles / raw$TotalCost | |
raw$AvgMPG <- raw$totalmiles / raw$Amount | |
costsummary <- ddply(raw, "Brand", function(x) data.frame(meancost = mean(x$Avgcost, na.rm=T))) | |
mpgsummary <- ddply(raw, "Brand", function(x) data.frame(meanMPG = mean(x$AvgMPG, na.rm=T))) | |
final <- merge(costsummary, mpgsummary) | |
ggplot(final, aes(x= meancost, y= meanMPG, label= Brand)) + | |
geom_point(size=4) +· | |
geom_text(aes(label= Brand), hjust= -0.2, vjust= -0.2, size=8) + | |
scale_x_continuous(limits = c(7,10)) + | |
ylab("mean MPG") + xlab("Mean cost") + | |
theme(axis.text.x = element_text(face='bold', size=20), | |
axis.text.y = element_text(face='bold', size=20), | |
axis.title.y = element_text(face="bold", size=20, angle=90), | |
axis.title.x = element_text(face="bold", size=20) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment