<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/data-visualization-part-3/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.stoltzmaniac.com/data-visualization-part-3/"> R-Projects – Stoltzmaniac</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>What Type of Data Visualization Do You Choose (if any)?</h3>
<p>Determining whether or not you need a visualization is <strong><em>step one</em></strong>. While it seems silly, this is probably something everyone (including myself) should be doing more often. A lot of times, it seems like a great way to showcase the amount of work you have been doing, but winds up being completely ineffective and could potentially harm what you’re doing. Once you determine that you actually need to visualize your data, you should have a rough idea of the options to look at. This post will explain and demonstrate some of the common types of charts and plots.</p>
<p><img title="plot of chunk unnamed-chunk-2" alt="plot of chunk unnamed-chunk-2" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-2-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>This is Part 3 in a series about Data visualization:</p>
<p><span></span></p>
<ul>
<li><a target="_blank" rel="nofollow" href="https://www.stoltzmaniac.com/data-visualization-part-1?utm_medium=SERIES&utm_source=DATA_VISUALIZATION_TOP">Data Visualization – Part 1</a></li>
<li><a target="_blank" rel="nofollow" href="https://www.stoltzmaniac.com/data-visualization-part-2?utm_medium=SERIES&utm_source=DATA_VISUALIZATION_TOP">Data Visualization – Part 2</a></li>
</ul>
<h4>Determine whether or not you actually need a visualizatoin in the first place.</h4>
<p>Like the best practices I listed in <a target="_blank" rel="nofollow" href="https://www.stoltzmaniac.com/data-visualization-part-1?utm_medium=SERIES&utm_source=DATA_VISUALIZATION_MID_ARTICLE">Data Visualization – Part 1</a>, make sure your visualizations:</p>
<ul>
<li>Are clearly illustrating a relevant point</li>
<li>Are tailored to the appropriate audience</li>
<li>Are tailored to the presentation medium</li>
<li>Are memorable to those who care about the material</li>
<li>Are increasing the understanding of the subject matter</li>
</ul>
<p>If these don’t seem possible, <strong><em>you probably don’t need a data visualization.</em></strong></p>
<h4>If you do need one, what’s a good first step to take?</h4>
<p>Take a look at the forum in which you’re presenting, it matters! If you are writing for a scientific journal, it will be different than presenting live to a thousand person audience. Think about a Ted Talk compared to the Journal of Physics.</p>
<p>Point being: <strong>consider your audience!</strong></p>
<p>Let’s talk about a high-level presentation. Everyone has seen a slideshow with fancy charts that add zero value. Do not be the person presenting something that way! Providing useless content will confuse the audience and/or lead to boredom.</p>
<p>If your point is to show year-over-year change of a single metric – show it as a simple number on the page in big bold font rather than a chart.</p>
<p>In this made up example, I am displaying revenue over the last few years (<strong><em>note: be more specific</em></strong> when it comes to what type of revenue you’re talking about).</p>
<p>Which of the following makes more sense to put on a slide?</p>
<p><img title="plot of chunk unnamed-chunk-3" alt="plot of chunk unnamed-chunk-3" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-3-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>If you agree with me, the one on the right will be much easier for people to understand in a presentation. It gets the point across without requiring processing which will allow people to focus on what is important. Any additional nuggets you would like to point out can be spoken to.</p>
<p>Now, let’s talk about publishing content that isn’t for academic use but will reach the public (i.e. newspapers, magazines, blogs, etc.). These types of charts can cover a wide range of topics so we’ll have to stick to the basics. We’re going to look at displaying information which is interesting and adds value.</p>
<p>Here is a great example from <a target="_blank" rel="nofollow" href="http://junkcharts.typepad.com/junk_charts/2017/04/what-does-lying-politicians-have-in-common-with-rainbow-colors.html">Junk Charts</a> in which the author of the original <a target="_blank" rel="nofollow" href="http://www.dailykos.com/story/2016/8/7/1556666/-Three-lessons-from-the-rise-of-Donald-Trump">Daily Kos Article</a> is showing a type of “lie detector” chart. The chart does a number of things well: it illustrates a relevant point, it is appropriate to the audience and medium, and really helps to understand the subject matter better. However, the original chart is too colorful which takes away from its effectiveness. Junk Charts took it to the next level by simplifying the colors and axes.</p>
<h4>Original Version (Daily Kos)</h4>
<p><img title="plot of chunk unnamed-chunk-4" alt="plot of chunk unnamed-chunk-4" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-4-1-2.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Modified Version (Junk Charts)</h4>
<p><img title="plot of chunk unnamed-chunk-5" alt="plot of chunk unnamed-chunk-5" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-5-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>By merely looking at this chart you can see how it is ranked, a sense of scale, the comparison between people, and clearly labeled names. Fantastic work!</p>
<p>Rather than going over more examples of work others are doing, please visit <a target="_blank" rel="nofollow" href="http://chartporn.org/">Chart Porn</a> (don’t worry about the name, it’s a great data visualization site) and <a target="_blank" rel="nofollow" href="http://junkcharts.typepad.com/">Junk Charts</a>. They have phenomenal examples of what to do (and what not to do) when publishing to the public.</p>
<h4>You have a point, now what?</h4>
<p>There is no rulebook as to how to display your data. However, as you have seen, there are both great and poor options. The choice is up to you – so think long and hard before making a decision (and you can always try a number of them out on people before publishing).</p>
<p><strong>Ask yourself the following questions to help drive your decision:</strong></p>
<ul>
<li>Are you making a comparison?</li>
<li>Are you finding a relationship?</li>
<li>Are you showing a distribution?</li>
<li>Are you finding a trend over time?</li>
<li>Are you showing composition?</li>
</ul>
<p>Once you know which question you are asking, it will keep your mind focused on the outcome and will quickly narrow down your charting options.</p>
<h4>Rule of Thumb</h4>
<ul>
<li><strong>Trend:</strong> Column, Line</li>
<li><strong>Comparison:</strong> Area, Bar, Bullet, Column, Line, Scatter</li>
<li><strong>Relationship:</strong> Line, Scatter</li>
<li><strong>Distribution:</strong> Bar, Boxplot, Column</li>
<li><strong>Composition:</strong> Donut, Pie, Stacked Bar, Stacked Column</li>
</ul>
<p>Obviously, there are plenty of choices beyond these, so don’t hesitate to use what works best. I will go over some of these basics and show some comparisons of poor charting techniques vs. slightly better ones.</p>
<p>For this project, I’ll use some oil production data that I found while digging through <a target="_blank" rel="nofollow" href="http://data.world/">http://data.world</a> (pretty great site). The data can be found <a target="_blank" rel="nofollow" href="http://www.eia.gov/dnav/pet/pet_crd_crpdn_adc_mbbl_m.htm">here</a></p>
<p>Let’s load up some libraries and get started.</p>
<pre>library(ggplot2)
library(dplyr)
library(tidyr)
library(lubridate)
library(scales)</pre>

<pre>#Custom data preparation
#GitHub (linked to at bottom of this post)
source('data_preparation.R')
data = getData()</pre>

<pre>head(data)</pre>

<pre>##   Location Month Year ThousandBarrel       Date
## 1  Alabama   Mar 2013            883 2013-03-01
## 2  Alabama   Apr 2013            844 2013-04-01
## 3  Alabama   May 2013            878 2013-05-01
## 4  Alabama   Feb 2013            809 2013-02-01
## 5  Alabama   Mar 1982           1687 1982-03-01
## 6  Alabama   Apr 1982           1567 1982-04-01</pre>

<hr>
<h2>Trend – Line Chart</h2>
<p><strong>Objective:</strong> Visualize a trend in oil production in the US from 1981 – 2016 by year. I want to illustrate the changes over the time period. This is a very high-level view and only shows us a decline followed by a ramp up at the end of the period.</p>
<h4>Poor Version</h4>
<p>The x-axis is a disaster and the y-axis isn’t formatted well. While it gets the point across, it’s still worthless.</p>
<pre>df = data %&amp;gt;% 
  group_by(Year) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))

p = ggplot(df,aes(x=Year,y=ThousandBarrel,group=1)) 
p + geom_line(stat='identity') + 
  ggtitle('Oil Production Over Time') + 
  theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5)) + 
  xlab('') + ylab('')</pre>
<p><img title="plot of chunk unnamed-chunk-7" alt="plot of chunk unnamed-chunk-7" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-7-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Better Version</h4>
<p>The title gives us a much better understanding of what we’re looking at. The chart is slightly wider and the axes are formatted to be legible.</p>
<pre>p = ggplot(df,aes(x=Year,y=ThousandBarrel,group=1)) 
p + geom_line(stat='identity') + 
  ggtitle('Thousand Barrel Oil Production By Year in the U.S.') +
  theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5)) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
  scale_y_continuous(labels = comma)</pre>
<p><img title="plot of chunk unnamed-chunk-8" alt="plot of chunk unnamed-chunk-8" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-8-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<hr>
<h2>Comparison – Line Chart</h2>
<p><strong>Objective</strong>: Identify which states affected the trend the most. Evaluate them simultaneously in order to paint the picture and compare their trends over the time period. From this visual you can see the top states are Alaska, California, Louisiana, Oklahoma, Texas and Wyoming. Texas seems to break the mold quite drastically and drove the spike which occurred after 2010.</p>
<h4>Poor Version</h4>
<p>There are far too many colors going on here. Everything at the bottom of the chart is relatively useless and takes our focus away from the big players.</p>
<pre>df = data %&amp;gt;%
  group_by(Location, Year) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))

df$Year = as.numeric(df$Year)

p = ggplot(df,aes(x=Year,y=ThousandBarrel,col=Location))
p + geom_line(stat='identity') + 
  ggtitle(paste('Oil Production By Year By State in the U.S.')) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))</pre>
<p><img alt="plot of chunk unnamed-chunk-9" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-9-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Better Version</h4>
<p>This focuses attention on the top producing states. It compares them to each other and shows the trend per state as well. Using facet_wrap() tends to be used in what’s known as “small multiples” – this is a technique which helps to break up the visual components of the data into easy-to-understand pieces which make intuitive sense.</p>
<pre>n=6 #Arbitrary at first, after trying a few, this made the most sense
topN = data %&amp;gt;%
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  arrange(-ThousandBarrel) %&amp;gt;%
  top_n(n)

df = data %&amp;gt;%
  filter(Location %in% topN$Location) %&amp;gt;%
  group_by(Year,Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))

df$Year = as.numeric(df$Year)
df$Location = as.factor(df$Location)

p = ggplot(df,aes(x=Year,y=ThousandBarrel,group=1))
p + geom_line(stat='identity') + 
  ggtitle(paste('Top',as.character(n),'States - Oil Production By Year in the U.S.')) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
  facet_wrap(~Location) + 
  scale_y_continuous(labels = comma)</pre>
<p><img alt="plot of chunk unnamed-chunk-10" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-10-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<hr>
<h2>Relationship – Scatter Plot</h2>
<p><strong>Objective</strong>: Check to see if data from Alaska and California is correlated. While this isn’t extremely interesting, it does allow us to use this same data set (sorry). The charts indicate that there appears to be a strong positive correlation between the two states.</p>
<h4>Poor Version</h4>
<p>Lots of completely irrelevant data! The size of the point should have nothing to do with the year.</p>
<pre>statesList = c('Alaska','California')
df = data %&amp;gt;%
  filter(Location %in% statesList) %&amp;gt;%
  spread(Location,ThousandBarrel) %&amp;gt;%
  select(Alaska,California,Month,Year)

p = ggplot(df,aes(x=Alaska,y=California,col=Month,size=Year))
p + geom_point() + 
  scale_y_continuous(labels = comma) +
  scale_x_continuous(labels = comma) +
  ggtitle('Oil Production - CA vs. AK') + 
  theme(plot.title = element_text(hjust = 0.5))</pre>
<p><img alt="plot of chunk unnamed-chunk-11" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-11-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Better Version</h4>
<p>The points are all the same size and a trend line helps to visualize the relationship. While it can sometimes be misleading, it makes sense with our current data.</p>
<pre>df = data %&amp;gt;%
  filter(Location %in% statesList) %&amp;gt;%
  spread(Location,ThousandBarrel) %&amp;gt;%
  select(Alaska,California,Year)

p = ggplot(df,aes(x=Alaska,y=California))
p + geom_point() + 
  scale_y_continuous(labels = comma) +
  scale_x_continuous(labels = comma) +
  ggtitle('Monthly Thousand Barrel Oil Production 1981-2016 CA vs. AK') + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  geom_smooth(method='lm')</pre>
<p><img alt="plot of chunk unnamed-chunk-12" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-12-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h2>Distribution – Boxplot</h2>
<p><strong>Objective</strong>: Examine the range of production by state (per year) to give us an idea of the variance. While the sums and means are nice, it’s quite important to have an idea of distributions. While it was semi-apparent in the line charts, the variance of Texas is huge compared to the others!</p>
<h4>Poor Version</h4>
<p>Alphabetical order doesn’t add any value, names are overlapping on top of each other. While you can tell who the big players are, this visual does not add the value it should.</p>
<pre>df = data %&amp;gt;%
  group_by(Year,Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))

p = ggplot(df,aes(x=Location,y=ThousandBarrel))
p + geom_boxplot() + 
  ggtitle('Distribution of Oil Production by State')</pre>
<p><img alt="plot of chunk unnamed-chunk-13" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-13-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Better Version</h4>
<p>This gives a nice ranking to the plot while still showing their distributions. We could take this a step further and separate out the big players from the small players (I’ll leave that up to you).</p>
<pre>p = ggplot(df,aes(x=reorder(Location,ThousandBarrel),y=ThousandBarrel))
p + geom_boxplot() + 
  scale_y_continuous(labels = comma) +
  ggtitle('Distribution of Annual Oil Production By State (1981 - 2016)') + 
  coord_flip()</pre>
<p><img alt="plot of chunk unnamed-chunk-14" src="https://i2.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-14-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h2>Composition – Stacked Bar</h2>
<p><strong>Objective</strong>: Check out the composition of total production by state. It’s interesting to see how the composition was relatively similar across decades until the 2010’s. Texas was 50% of the output!</p>
<h4>Poor Version</h4>
<p>My favorite, the beautiful pie chart! There’s nothing better than this… (no need for further commentary).</p>
<pre>df = data %&amp;gt;%
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  mutate(ThousandBarrel = ThousandBarrel/sum(ThousandBarrel))

df$ThousandBarrel = round(100*df$ThousandBarrel,0)

library(plotrix)
pie(x=df$ThousandBarrel,labels=df$Location,explode=0.1,col=rainbow(nrow(df)),main='Percentage of Oil Production by State')</pre>
<p><img alt="plot of chunk unnamed-chunk-15" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-15-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h4>Better Version</h4>
<p>The 1980’s and 2010’s will be missing years in terms of a “decade” due to the data provided (and it’s only 2017). While the percentage labels are slightly off center, it’s certainly much better than the pie chart. It’s not quite “apples-to-apples” for a comparison because I created different decades, but you get the idea.</p>
<p>I also created an “Other” category in order to simplify the output. When you are doing comparisons, it’s typically a good idea to find a way to reduce the number of variables in the output while not removing data by dropping it completely – <strong>do this carefully and transparently!</strong></p>
<pre>data$Decade = '1980s'
data$Decade[data$Year &amp;gt;= 1990] = '1990s'
data$Decade[data$Year &amp;gt;= 2000] = '2000s'
data$Decade[data$Year &amp;gt;= 2010] = '2010s'
data$Decade = as.factor(data$Decade)

top5 = data %&amp;gt;%
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  arrange(-ThousandBarrel) %&amp;gt;%
  top_n(5) %&amp;gt;%
  select(Location)

top5List = top5$Location

data$State = &quot;Other&quot;

for(i in 1:length(top5List)){
  data$State[data$Location == top5List[i]] = top5List[i]
}

df = data %&amp;gt;%
  group_by(Decade,State) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  mutate(ThousandBarrel = ThousandBarrel/sum(ThousandBarrel))

df$ThousandBarrel = round(df$ThousandBarrel,3)
df$text = paste(round(100*df$ThousandBarrel,0),'%', sep='')

p = ggplot(df,aes(x=Decade,y=ThousandBarrel,col=reorder(State,ThousandBarrel),fill=reorder(State,ThousandBarrel)))
p + geom_bar(stat='identity') + 
  geom_text(aes(label=text),col='Black',size = 4, hjust = 0.5, vjust = 3, position = &quot;stack&quot;) + 
  scale_y_continuous(labels = percent) +
  ggtitle('Percentage of Top Oil Producing States by Decade') + 
  guides(fill=guide_legend(title='State'),col=guide_legend(title='State')) + 
  theme(plot.title = element_text(hjust = 0.5))</pre>
<p><img alt="plot of chunk unnamed-chunk-16" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-16-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<h3>Some other fun concepts are below!</h3>
<p>Some of them are nice, others are terrible! I won’t comment on any of them, but I felt it was necessary to include some other ideas I toyed around with.</p>
<p>Have fun with your data visualizations: be creative, think outside the box, use tools other than computers if it makes sense, fail often but learn quickly. I’m sure I’ll think of a thousand better ways to have illustrated the concepts in this post by tomorrow, so I’ll make updates as I think of them!</p>
<p>Now it’s your turn!</p>
<p>As always, the code used in this post is on my <a target="_blank" rel="nofollow" href="https://github.com/stoltzmaniac/Data-Visualization-Lesson">GitHub</a></p>
<pre>df = data %&amp;gt;% 
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  arrange(-ThousandBarrel)
p = ggplot(df,aes(x=reorder(Location,ThousandBarrel),y=ThousandBarrel))
p + geom_bar(stat='identity') + 
  ggtitle('Oil Production 1981 - 2016 By Location') + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  coord_flip()</pre>
<p><img alt="plot of chunk unnamed-chunk-17" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-17-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<pre>top10 = data %&amp;gt;%
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) %&amp;gt;%
  arrange(-ThousandBarrel) %&amp;gt;%
  top_n(10)</pre>

<pre>## Selecting by ThousandBarrel</pre>

<pre>print(top10)</pre>

<pre>## # A tibble: 10 × 2
##       Location ThousandBarrel
##          &amp;lt;chr&amp;gt;          &amp;lt;dbl&amp;gt;
## 1        Texas       23447172
## 2       Alaska       15775279
## 3   California        9988225
## 4    Louisiana        4267246
## 5     Oklahoma        3701224
## 6      Wyoming        2894624
## 7       Kansas        1708873
## 8     Colorado        1288643
## 9         Utah         894657
## 10 Mississippi         861999</pre>

<pre>df = data %&amp;gt;% 
  group_by(Location,Year) %&amp;gt;%
  filter(Location %in% top10$Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel)) 
p = ggplot(df,aes(x=Year,y=ThousandBarrel,col=Location,fill=Location))
p + geom_bar(stat='identity') + 
  ggtitle('Oil Production - Top 10 States') + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))</pre>
<p><img alt="plot of chunk unnamed-chunk-18" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-18-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<pre>df = data %&amp;gt;%
  filter(Year == 1990)%&amp;gt;%
  group_by(Location) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))
df$Location = tolower(df$Location)

#Add States without data
States = data.frame(Location = tolower(as.character(state.name)))
missingStates = States$Location[!(States$Location %in% df$Location)]
appendData = data.frame(Location=missingStates,ThousandBarrel=0)
df = rbind(df,appendData)

states_map &amp;lt;- map_data(&quot;state&quot;)

ggplot(df, aes(map_id = Location)) + 
    geom_map(aes(fill=ThousandBarrel), map = states_map) +
    expand_limits(x = states_map$long, y = states_map$lat)</pre>
<p><img alt="plot of chunk unnamed-chunk-19" src="https://i1.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-19-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<pre>df = data %&amp;gt;% 
  filter(Location == 'Texas') %&amp;gt;%
  group_by(Year,Month) %&amp;gt;%
  summarise(ThousandBarrel = sum(ThousandBarrel))

p = ggplot(df,aes(x=Month,y=ThousandBarrel))
p + geom_line(stat='identity',aes(group=Year,col=Year)) + 
  ggtitle('Oil Production By Year in the U.S.') + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1))</pre>
<p><img alt="plot of chunk unnamed-chunk-20" src="https://i0.wp.com/www.stoltzmaniac.com/wp-content/uploads/2017/04/unnamed-chunk-20-1-4.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.stoltzmaniac.com/data-visualization-part-3/"> R-Projects – Stoltzmaniac</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/JYaNAXu7e8I"></a></div>