<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/mapping-the-best-states-for-business/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.sharpsightlabs.com/blog/map-best-states-business/"> r-bloggers | SHARP SIGHT</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/best-states-for-business_map-600x425.png?w=450" alt="" class="wp-image-3436" data-recalc-dims="1"></a></p>
<p> </p>
<h2>Data science gives you tools to find opportunities</h2>
<p>A few months ago, I wrote a blog post about <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/new-amazon-hq/" target="_blank">Amazon’s search for a location for a second headquarters</a>. For those of you who don’t know about it, the technology giant – which currently has its headquarters in Seattle Washington – announced last September that it is planning to build a new second headquarters.</p>
<p>Over the last few weeks, this question of where Amazon will build its second headquarters opened a new question in my mind: what locations are <em>generally</em> great for business?</p>
<p>As an entrepreneur myself, I am personally interested in this question. Moreover, in a world that is increasingly driven by entrepreneurship and innovative business, this is something that we all need to consider. Whether you’re an entrepreneur or an employee, you need to think about where the best opportunities are. For example, as a data scientist, you need to think about where great jobs are <em>today</em>, but also where they might be 5 to 10 years from now.</p>
<p>Speaking more broadly though, this is the sort of question you’ll need to answer as a data scientist. In many cases, data scientists need to use visualization and other techniques to find opportunities.</p>
<h3>Your business partners will need you to answer questions and find opportunities</h3>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/blog/data-visualizations-are-tools-and-what-youre-building/" target="_blank">Finding insights</a> and identifying opportunities is a major part of the job for many data scientists. This is particularly true for junior data scientists. At beginning levels, most data scientists are not going to be working on machine learning systems and large software projects. Instead, many junior data scientists perform data analysis in order to find insights in data.</p>
<p>That being said, if your goal is to become a data scientist, <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/shipping-analysis-r-data-wrangling/" target="_blank">you need to be able to analyze data</a>, find insights, and identify opportunities.</p>
<p>For example, your business partners will want you to answer things like:</p>
<ul>
<li>“what market is performing best?”</li>
<li>“which customer segment should we target?”</li>
<li>“where is our greatest opportunity for improvement?”</li>
</ul>
<p>Of course, the specific questions will be different depending on what industry you’re working in, but the general purpose of the questions will be similar. Your business partners will typically want to improve something (i.e., profit, RIO, process performance, etc.) or gather information to make a good business decision. They’ll want you to find insights in data to help them with their problem.</p>
<p>Finding insights is a skill you need to develop if you want to get a data science job.</p>
<h3>Practice finding insights by asking and answering questions</h3>
<p>Finding insights in data is a skill, and like any skill, you’ll get better at it with practice.</p>
<p>A great way to practice finding insights in data is just answering your own questions about the world.</p>
<p>When you find yourself asking a question about the world, see if you can find a good dataset that might help you answer your question. If you can find a good dataset, analyze the data. Create some visualizations. See if you can use your data skills to find insights and answer your own questions.</p>
<p>This is particularly useful if you’re not working as a data scientist yet. To become a great data scientist, you need to practice by <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/choose-project-practice-data-science/" target="_blank">working on a lot of projects</a>. Of course, if you already have a job as a data scientist, you’ll get plenty of projects at work (trust me). But if you haven’t landed your first data science job, you’ll need to find your own projects to help you practice.</p>
<p>That being said, when you have a question like “what’s the best state for business,” go online, look for a dataset, and start writing a script to analyze it. You can use these questions as opportunities to work on a small project. Over time, working on small projects like this will sharpen your data skills.</p>
<h2>Mapping the best states for business</h2>
<p>After asking myself “what is the best state for business,” I went online and found some survey data from chiefexecutive.net to help answer the question. chiefexecutive.net surveyed several hundred CEOs and asked them to rank their favorite states for business. By visualizing this survey data, I’m able to gain some insight and answer the question “what is the best state for business.”</p>
<p>Again, this is <em>very similar</em> to the sorts of questions that you’ll get from business partners in a data science job. Therefore, when you ask yourself one of these questions, it’s a great opportunity to find a dataset and do some simple analysis. It’s a great opportunity to <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/choose-project-practice-data-science/" target="_blank">practice your data science skills</a>. If you get into the habit of answering questions like these yourself, you’ll be ready when you’re working as a real data scientist.</p>
<h2>Code: mapping the best states for business</h2>
<p>After finding a dataset from chiefexecutive.net, I wrote a quick R script to visualize the data. You’ll find the code below.</p>
<p>In the code, pay attention to what I’m doing here. I’ve used several critical skills from the data science workflow: getting data, cleaning data, and visualizing data.</p>
<p>To get the data, I’ve used some tools from <code>rvest</code> to scrape the data from the webpage.</p>
<p>I’ve used <code>dplyr</code> to <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/dplyr-intro-data-manipulation-with-r/" target="_blank">“wrangle” the data</a>. In particular, I’ve used <code>dplyr::select()</code> to reorder the variables. I also used <code>dplyr::mutate()</code> in combination with <code>stringr::str_to_lower()</code> to change some of the data to lower case.</p>
<p>Also pay attention to some of the visualization techniques and tools I’m using. For starters, to visualize this I’m just using <code>ggplot()</code>, although using <code>geom_map()</code> makes it a little more complicated. </p>
<p>Ultimately though, what makes this visualization look good is the detailed formatting. With that in mind, carefully look at the theme code. I’ve used <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/format-titles-and-axes-in-ggplot2/" target="_blank">the ggplot <code>theme()</code> function</a> to carefully control the appearance of the visualization. I’ve also used <code>scale_fill_gradientn()</code> to create the red/yellow/green color scale, which is critical for the appearance of the plot. Ultimately, it’s the formatting and color scale that really make this visualization work, so make sure that you learn how to use those tools.</p>
<p>That said, this code may look a little complicated to a beginner, but keep in mind that there are actually only a few dozen tools that you need to learn to create this.</p>
<p>A few dozen tools. That’s it. </p>
<p>If you studied diligently and practiced, how fast could you learn memorize a few dozen R functions?</p>
<pre class="wp-code-highlight">
#==============
# LOAD PACKAGES
#==============
library(tidyverse)
library(rvest)
library(stringr)
library(fiftystater)


#=============
# READ WEBPAGE
#=============
html.business &lt;- read_html(&quot;https://chiefexecutive.net/2017-best-worst-states-business/&quot;)


#============
# SCRAPE DATA
#============
html.business %>% 
  html_nodes('table') %>%
  .[[1]] %>%
  html_table() ->
  df.business


# CHECK COLUMN NAMES
df.business %>% colnames()


#====================
# CHANGE COLUMN NAMES
#====================
colnames(df.business) &lt;- c('rank_2017'
                           ,'state'
                           ,'text'
                           ,'rank_2016'
                           ,'change_in_rank'
                           )


#=================
# COERCE TO TIBBLE
#=================
df.business %>%
  as_tibble() ->
  df.business


# INSPECT
df.business %>% glimpse()


#==================
# REORDER VARIABLES
#==================
df.business %>% 
  select(state
         ,rank_2016
         ,rank_2017
         ,change_in_rank
         ,text
         ) ->
  df.business


#========
# GET MAP
#========
map.usa &lt;- map_data('state')

# inspect
map.usa %>% glimpse()


#==========================
# UN-CAPITALIZE STATE NAMES
#==========================
df.business %>%
  mutate(state = str_to_lower(state)) ->
  df.business


#=============
# CREATE THEME
#=============
theme.map &lt;- theme(
  text = element_text(family = 'Helvetica Neue', color = '#444444')
  ,panel.background = element_rect(fill = '#DDDDDD')
  ,plot.background = element_rect(fill = '#DDDDDD')
  ,legend.background = element_blank()
  ,legend.position = c(.9, .4)
  ,legend.key = element_blank()
  ,panel.grid = element_blank()
  ,plot.title = element_text(size = 18, face = 'bold')
  ,plot.subtitle = element_text(size = 12)
  ,axis.text = element_blank()
  ,axis.ticks = element_blank()
  ,axis.title = element_blank()
  )


#=====
# PLOT
#=====

ggplot(df.business, aes(map_id = state)) +
  geom_map(aes(fill = rank_2017), map = fifty_states) +
  expand_limits(x = fifty_states$long, y = fifty_states$lat) +
  theme.map +
  scale_fill_gradientn(colours = c('#009900','yellow', 'red')
                       ,breaks = c(1,10,20,30,40,50)) +
  labs(fill = str_c('Rank of best states\n'
                    ,'for business, 2017\n'
                    )
       ,title = str_c('New York, California, and Illinois '
                      ,'rank very low among CEOs'
                      )
       ,subtitle = str_c('chiefexecutive.net surveyed hundreds of CEOs and asked which states they prefered.\n'
                         ,'Large &quot;blue state&quot; states like California, Illinois, and New York ranked at the bottom\n'
                         ,'while Texas and Florida ranked at the top.  2017 is the 13th straight year with Texas\n'
                         ,'in the #1 position.\n'
                         )
       ) +
  guides(fill = guide_colourbar(reverse = T)) +
  coord_map(&quot;albers&quot;, lat0 = 30, lat1 = 40) +
  annotate(geom = 'text'
           ,label = 'data source: chiefexecutive.net/2017-best-worst-states/'
           ,x = -85, y = 22
           ,size = 3
           ,color = '#666666'
           )
</pre>
<p> </p>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank"><img sizes="(max-width: 600px) 100vw, 600px" src="https://i1.wp.com/www.sharpsightlabs.com/wp-content/uploads/2018/04/best-states-for-business_map-600x425.png?w=450" alt="" class="wp-image-3436" data-recalc-dims="1"></a></p>
<p> </p>
<h1>It should take only a few months to learn this</h1>
<p>Using data visualization to find insights in data is a skill, and it can be learned.</p>
<p>The bad news is that many people take a very long time to learn to do this. Most people will take over a year to learn to write code like this. Even worse, many people will try and fail (or give up), so they will <em>never</em> learn to write code like this.</p>
<p>I’m not pointing this out to be mean. I’m sympathetic to the fact that learning data science is hard. It’s confusing. And it takes time.</p>
<p>Having said that, I believe that a motivated, disciplined student could learn to write code like this in a few months. And when I say “learn” I don’t mean watch a few videos and have a rough idea about how it works. I mean that a motivated student could be able to write this code “fluently” after about 3 to 6 months; they should be able to <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/are-you-fluent-r/" target="_blank">write this code mostly from memory</a>. </p>
<h1>Discover how to master data science</h1>
<p>Finding insights in data takes practice. Learning the tools of data science is hard work.</p>
<p>… but if you know <em><strong>how</strong></em> to practice, you can master data science faster than you thought possible.</p>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank">Sign up now</a>, and discover how to master data science <strong><em>fast</em></strong>. </p>
<p>In our tutorials, we will help you rapidly learn and master the tools you need to be a top-performing data scientist.</p>
<p>Moreover, if you sign up now, you’ll get access to our <strong>free</strong> Data Science Crash Course.</p>
<p>In the Data Science Crash Course, you’ll learn:</p>
<ul>
<li>a step-by-step data science learning plan </li>
<li>the 1 programming language you <i>need to</i> learn </li>
<li>3 essential data visualizations</li>
<li>how to do data manipulation in R</li>
<li>how to get started with machine learning</li>
<li>the difference between machine learning and statistics</li>
</ul>
<p><a rel="nofollow" href="http://www.sharpsightlabs.com/join-newsletter-get-crash-course/" target="_blank">
<p><strong>SIGN UP NOW</strong></p>
<p></p></a>
<p>The post <a rel="nofollow" href="http://www.sharpsightlabs.com/blog/map-best-states-business/" target="_blank">Mapping the best states for business</a> appeared first on <a rel="nofollow" href="http://www.sharpsightlabs.com/" target="_blank">SHARP SIGHT</a>.</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="http://www.sharpsightlabs.com/blog/map-best-states-business/"> r-bloggers | SHARP SIGHT</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/p_o88wzRhT0" height="1"></a></div>