Graphing my MPG vs Temperature

December 9, 2013

(This article was first published on Stats and things, and kindly contributed to R-bloggers)

I use Fuelly to track the fuel mileage in my Toyota Tundra pickup truck. They have a mobile app, so while I’m waiting for the truck to fill up, I log the odometer, and the number of gallons that I put in and then also the price per gallon of fuel and an estimate of my city driving percentage.

Any how, I’ve noticed a substantial drop in fuel economy when the weather turns cold. So, remembering that I’ve decided to record the temperature at O’hare every day, I figured I’d try to take a look at the data. Now, I live 40 miles or so north of O’hare, so it’s not perfect, but it was a good estimate.

To merge the daily temperature data with the sporadic fillup data, I chose to take the average high temperature for the days between the fillup[i] and fillup[i-1] to use as temperature[i]. I hope that makes sense. Basically, I take the average temperature over the tank of gas.

Let’s see what a simple graph of average temperature by MPG looks like…

There’s a fairly obvious pattern here. As temperature goes up, my MPG goes up, just as I suspected was happening.

Now, I know this next graph goes against normal data visualization guidelines, but I just think it makes the relationship easier to understand for a lay person. Here, I’ve plotted both temperate and MPG on the same graph, with MPG in black with it’s axis on the left and temperature in red with it’s axis on the right.

Now, as I’m facing the beginning of a winter, I suppose I can be fairly certain of seeing poor fuel economy for the next few months. My wallet will appreciate the spring warm up.

Credit to this guy, for his dual axis ggplot2 code.

R code available on github here.
Follow me on twitter…

To leave a comment for the author, please follow the link and comment on their blog: Stats and things. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)