Principles of Data Visualization and Introduction to ggplot2

I have provided you with data about the 5,000 fastest growing companies in the US, as compiled by Inc. magazine. lets read this in:

inc <- read.csv("https://raw.githubusercontent.com/charleyferrari/CUNY_DATA_608/master/module1/Data/inc5000_data.csv", header= TRUE)

And lets preview this data:

##   Rank                         Name Growth_Rate   Revenue
## 1    1                         Fuhu      421.48 1.179e+08
## 2    2        FederalConference.com      248.31 4.960e+07
## 3    3                The HCI Group      245.45 2.550e+07
## 4    4                      Bridger      233.08 1.900e+09
## 5    5                       DataXu      213.37 8.700e+07
## 6    6 MileStone Community Builders      179.38 4.570e+07
##                       Industry Employees         City State
## 1 Consumer Products & Services       104   El Segundo    CA
## 2          Government Services        51     Dumfries    VA
## 3                       Health       132 Jacksonville    FL
## 4                       Energy        50      Addison    TX
## 5      Advertising & Marketing       220       Boston    MA
## 6                  Real Estate        63       Austin    TX
##       Rank                          Name       Growth_Rate     
##  Min.   :   1   (Add)ventures         :   1   Min.   :  0.340  
##  1st Qu.:1252   @Properties           :   1   1st Qu.:  0.770  
##  Median :2502   1-Stop Translation USA:   1   Median :  1.420  
##  Mean   :2502   110 Consulting        :   1   Mean   :  4.612  
##  3rd Qu.:3751   11thStreetCoffee.com  :   1   3rd Qu.:  3.290  
##  Max.   :5000   123 Exteriors         :   1   Max.   :421.480  
##                 (Other)               :4995                    
##     Revenue                                  Industry      Employees      
##  Min.   :2.000e+06   IT Services                 : 733   Min.   :    1.0  
##  1st Qu.:5.100e+06   Business Products & Services: 482   1st Qu.:   25.0  
##  Median :1.090e+07   Advertising & Marketing     : 471   Median :   53.0  
##  Mean   :4.822e+07   Health                      : 355   Mean   :  232.7  
##  3rd Qu.:2.860e+07   Software                    : 342   3rd Qu.:  132.0  
##  Max.   :1.010e+10   Financial Services          : 260   Max.   :66803.0  
##                      (Other)                     :2358   NA's   :12       
##             City          State     
##  New York     : 160   CA     : 701  
##  Chicago      :  90   TX     : 387  
##  Austin       :  88   NY     : 311  
##  Houston      :  76   VA     : 283  
##  San Francisco:  75   FL     : 282  
##  Atlanta      :  74   IL     : 273  
##  (Other)      :4438   (Other):2764

Think a bit on what these summaries mean. Use the space below to add some more relevant non-visual exploratory information you think helps you understand this data:

The summaries above provide important information regarding our dataset. However, the output of the summary base function in R can make it difficult to fully appreciate this type of data overview. Before adding more information, I chose to start the exploration by re-formatting the summary statistics of the numeric variables. This output made it easier for me to understand the variables we are working with.

Summary Statistics of Numeric Variables
N Missing Mean SD Min Q1 Median Q3 Max
Rank 5001 0 2501.64 1443.51 1.0e+00 1.252e+03 2.502e+03 3.751e+03 5.0000e+03
Growth_Rate 5001 0 4.61 14.12 3.4e-01 7.700e-01 1.420e+00 3.290e+00 4.2148e+02
Revenue 5001 0 48222535.49 240542281.14 2.0e+06 5.100e+06 1.090e+07 2.860e+07 1.0100e+10
Employees 4989 12 232.72 1353.13 1.0e+00 2.500e+01 5.300e+01 1.320e+02 6.6803e+04

As shown in the initial summary table, most of our factor variables contain too many levels for this function to be useful. For example, City contained 1519 levels and Name contained 5001. Industry, on the other hand, contained 25 levels, so I choose to use the dplyr package to know the major states and industries within this data set.

ind.state <- inc %>% 
  group_by(Industry, State) %>% 
  count(Industry) %>% 
  spread(Industry, n) %>% 
  adorn_totals(c("col", "row")) %>%
  top_n(10, Total) %>%
  arrange(Total) %>%
  t()

As outlined below, California has the highest participation in our collected data. And, IT Services is the largest industry reported in this frame.

Top 10 States across in ‘inc’ Industries
State MA OH GA IL FL VA NY TX CA Total
Advertising & Marketing 19 13 14 28 31 16 57 24 91 471
Business Products & Services 15 19 17 25 27 17 26 40 69 482
Computer Hardware NA 1 3 5 1 3 1 NA 17 44
Construction 6 7 9 10 18 8 6 16 17 187
Consumer Products & Services 6 2 7 10 14 4 17 20 38 203
Education 3 1 NA 8 3 2 14 6 13 83
Energy 6 5 1 2 3 1 5 29 16 109
Engineering 4 6 NA 2 3 2 4 5 10 74
Environmental Services 2 3 1 1 1 3 2 7 6 51
Financial Services 9 11 13 12 10 10 13 23 44 260
Food & Beverage 5 3 5 13 3 1 9 9 26 131
Government Services 3 3 2 1 12 83 1 6 7 202
Health 19 16 16 16 26 6 13 31 33 355
Human Resources 5 9 18 11 9 7 11 11 23 196
Insurance 2 2 2 1 6 NA 2 3 8 50
IT Services 29 27 44 48 35 69 43 54 82 733
Logistics & Transportation 3 15 8 16 11 8 4 8 14 155
Manufacturing 6 22 12 22 7 2 13 19 21 256
Media 1 3 2 3 2 2 11 1 12 54
Real Estate 4 2 5 6 7 4 4 11 16 96
Retail 6 6 7 7 17 5 14 15 33 203
Security 1 2 5 5 3 3 4 7 9 73
Software 16 4 13 14 16 18 13 24 65 342
Telecommunications 6 4 8 6 8 6 17 10 23 129
Travel & Hospitality 6 NA NA 1 9 3 7 8 8 62
Total 182 186 212 273 282 283 311 387 701 5001

Lastly, I chose to explore the linear relationship between Growth_Rate and Revenue. The low R^2 value suggests that the variability within this model cannot be explained using a linear model.

summary(lm(Growth_Rate ~ Revenue, data = inc))
## 
## Call:
## lm(formula = Growth_Rate ~ Revenue, data = inc)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -7.92  -3.84  -3.19  -1.32 416.84 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 4.594e+00  2.037e-01  22.552   <2e-16 ***
## Revenue     3.702e-10  8.304e-10   0.446    0.656    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 14.12 on 4999 degrees of freedom
## Multiple R-squared:  3.974e-05,  Adjusted R-squared:  -0.0001603 
## F-statistic: 0.1987 on 1 and 4999 DF,  p-value: 0.6558

Question 1

Create a graph that shows the distribution of companies in the dataset by State (ie how many are in each state). There are a lot of States, so consider which axis you should use. This visualization is ultimately going to be consumed on a ‘portrait’ oriented screen (ie taller than wide), which should further guide your layout choices.

Question 2

Lets dig in on the state with the 3rd most companies in the data set. Imagine you work for the state and are interested in how many people are employed by companies in different industries. Create a plot that shows the average and/or median employment by industry for companies in this state (only use cases with full data, use R’s complete.cases() function.) In addition to this, your graph should show how variable the ranges are, and you should deal with outliers.

Top 3 States with Most Companies
State NY TX CA
Freq 311 387 701

Question 3

Now imagine you work for an investor and want to see which industries generate the most revenue per employee. Create a chart that makes this information clear. Once again, the distribution per industry should be shown.