- Part 1: Cleaning data
- Part 2: Visualizing trends in fuel prices
- Part 3: Seasonal trends in fuel prices
- Part 4: Bias in car-reported fuel efficiency
Storing the Data
The way I collected the data was rather straight forward. Every time I got gas from a gas station I would take my receipt (which conveniently had how much I paid, the city/date, the price per gallon, how many gallons) and wrote on it the information as reported by my car. Every so often when I had 4 or 5 of these receipts my wife would complain and I would take them inside and record the information to my spreadsheet.I was using Google Sheets for keeping track of this data. I chose Google Sheets for three reasons:
- It was free and I already had an account with Google (no need to buy a license for Microsoft Excel)
- I could easily add information to the sheet from my home/work computer or even from my phone (the cloud is a powerful thing).
- I could quickly make charts and graphs in Google Sheets to visualize the data
I hear you asking "wait... if you could make charts in Google Sheets, then why bother with Tableau at all?" It turns out, plotting in Google Sheets is fairly limited. I want to try out the tools that are used by members of the Data Science community. Tableau has come up a few times in my research as a useful tool, so I decided to poke around my fuel data using Tableau. Tableau also has a nifty feature for just loading Google Sheets, so that was another bonus.
Starting Slow
The first step in this short stroll through Tableau is to load the data. Fortunately, Tableau provides a quick import for loading Google Sheets data. On opening a new Tableau notebook, I'm greeted with the following screen, which allows me to load directly from a Google Sheet (identified by a red box):![]() |
| A brand new Tableau book |
![]() |
| Loaded my Google Sheet into Tableau |
Scatter plotting
In my humble opinion, the very basic, most rudimentary plot that can be made is a scatter plot. I have data points with two parameters, <X,Y>, put them on a plot. Simple right? So, let's take a look at Tableau and see if we can figure out how to do this. There are three different options for new tabs on the bottom. You can create a new "worksheet", "dashboard", or "story". The thing I want for creating a new plot is going to be a worksheet, so let's open up a new one of those. We can do that easily by clicking on the 'New Worksheet' button on the bottom of the screen. This opens a clean sheet for us to start playing around in:![]() |
| New worksheet with the 'New Worksheet' button highlighted |
It won't let me drag and drop them into those places. So instead let's use the 'Show Me' button in the upper right to see what we need to make that plot. For a 'scatter plot' I need "2-4 measures" values. So how do I make the date a measure? Seriously, how do I do that? I couldn't figure it out, so I just went with a line plot, but even that gives us a weird result:
![]() |
| THIS IS NOT WHAT I WANTED! |
![]() |
| Finally, it looks like what I wanted |
Applying Filters
Now that we have a decent plot, let's apply some data selection by removing 'nulls' and data from outside my home town. Removing nulls is easy they're actually already gone. I'm just gonna click that '20 nulls' button in the lower right corner to get rid of it now. There, OCD satisfied. To apply the cuts on geographic location, we go back to the 'Data Source' tab and select 'filters | add' in the upper right. We'll add two filters, one for 'Latitude' and one for 'Longitude'.
Histograms
After a simple scatter plot, one of the types of plots I find most helpful is a histogram. It helps me to visualize the distribution of actual values in the data. In Tableau, this is pretty easy.
- We just select the measure we want (for this example I'll stick to 'Real MPG')
- Select the 'histogram' option under 'Show Me'
![]() |
| Steps to create a histogram |
This generates a histogram that looks like this:
![]() |
| Generated histogram of 'Real MPG' values |
That wasn't so hard! Later we'll see how to color the histogram by data.
Adding a Moving Average
So we've reduced spurious points that are adding noise into our plot, but it's still really messy. We can add a moving average to help us better visualize what the trend in the points is over time. This was perhaps one of the hardest things I did in all parts of this experience. First, I wasn't able to just right-click the data in the 'Rows' field and select 'add moving average'. You can add a trend line, but that's not what we want.
What you need to do is to create an entirely new field under 'Measures' (on the far left). For the moving average, we create something that looks like this:
WINDOW_AVG(AVG[Real MPG], -2, 2)
and we'll call it 'Real MPG Moving Avg'. Now we want to plot it. Should be as simple as dragging it up to the 'Rows' place, but it doesn't let us do that. What we have to do is select again the 'Date', 'Real MPG', and our new 'Real MPG Moving Avg' variable and then we can plot them:
![]() |
| MPG and Moving Avg MPG on the same plot |
![]() |
| Finally, the plot we were trying to make! |
Adding color to the points
One of the things I do repeatedly to visualize the trend over time is to color the points by either exact date, or by financial quarter. I use these two different styles to convey different points:- Color by exact date: This helps visualize trends that take place gradually over the entire study. For instance, in part 4, coloring the entries in the MPG histogram by date helps visualize how the distribution gradually shifts to lower MPG over the 4 years.
- Color by financial quarter: Most of the data doesn't necessarily have to do with financial information, however, the financial quarters do line up with the seasons quite nicely. Coloring by quarter allows visualizing differences based on the season regardless of the year. For example, visualizing the changing cost of fuel and fuel efficiency by season helped me learn that there are seasonal trends in fuel prices.
For my purposes, I was very interested in seeing how various measures changed over time. Because of this, I used time information to color the data points in my plots. This is as simple as
And we can also make the same plot with our histogram above:
Interesting to see that the distribution appears to shift lower year after year.
There's no requirement though to use time information and I could have just as easily used any measure or dimension value.
- Drag the 'Date' dimension into the 'Marks' box for the item we want to color
- Make sure the menu item just to the left of the dragged object is set to 'color'
![]() |
| Real MPG with points colored by year |
![]() |
| Histogram with values colored by year |
There's no requirement though to use time information and I could have just as easily used any measure or dimension value.


















