Graphing my MPG vs Temperature

[This article was first published on Stats and things, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)