Principles of Data Visualization and Introduction to ggplot2

HW01_01
HW01_02
The following dplyr functions are used in this homework:
dplyr
 select
 filter
 arrange
 mutate
 summarise
 group_by
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.2
Read the data from the .CSV file into R.
inc5000_df = read.csv(file="Data/inc5000_data.csv", header=TRUE, sep=",")
nrow(inc5000_df)
## [1] 5001
head(inc5000_df, 20)
##    Rank                         Name Growth_Rate   Revenue                     Industry Employees          City State
## 1     1                         Fuhu      421.48 1.179e+08 Consumer Products & Services       104    El Segundo    CA
## 2     2        FederalConference.com      248.31 4.960e+07          Government Services        51      Dumfries    VA
## 3     3                The HCI Group      245.45 2.550e+07                       Health       132  Jacksonville    FL
## 4     4                      Bridger      233.08 1.900e+09                       Energy        50       Addison    TX
## 5     5                       DataXu      213.37 8.700e+07      Advertising & Marketing       220        Boston    MA
## 6     6 MileStone Community Builders      179.38 4.570e+07                  Real Estate        63        Austin    TX
## 7     7        Value Payment Systems      174.04 2.550e+07           Financial Services        27     Nashville    TN
## 8     8         Emerge Digital Group      170.64 2.390e+07      Advertising & Marketing        75 San Francisco    CA
## 9     9                    Goal Zero      169.81 3.310e+07 Consumer Products & Services        97     Bluffdale    UT
## 10   10                     Yagoozon      166.89 1.860e+07                       Retail        15       Warwick    RI
## 11   11                       OBXtek      164.33 2.960e+07          Government Services       149 Tysons Corner    VA
## 12   12                       AdRoll      150.65 3.410e+07      Advertising & Marketing       165 San Francisco    CA
## 13   13                   uBreakiFix      141.02 1.700e+07                       Retail       250       Orlando    FL
## 14   14                        Sparc      128.63 2.110e+07                     Software       160    Charleston    SC
## 15   15                 LivingSocial      123.33 5.360e+08 Consumer Products & Services      4100    Washington    DC
## 16   16               Amped Wireless      110.68 1.430e+07            Computer Hardware        26         Chino    CA
## 17   17            Intelligent Audit      105.73 1.450e+08   Logistics & Transportation        15 Rochelle Park    NJ
## 18   18            Integrity Funding      104.62 1.110e+07           Financial Services        11      Sarasota    FL
## 19   19         Vertex Body Sciences      100.10 1.180e+07              Food & Beverage        51      columbus    OH
## 20   20                      BlueKai       92.45 2.680e+07      Advertising & Marketing       107     Cupertino    CA
(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 assuming I am using a ‘portrait’ oriented screen (ie taller than wide).
inc5000State_df = as.data.frame(inc5000_df %>% group_by(State) %>% summarise( TotalCompanies = n()))
inc5000State_df = arrange(inc5000State_df, desc(TotalCompanies))
nrow(inc5000State_df)
## [1] 52
print(inc5000State_df)
##    State TotalCompanies
## 1     CA            701
## 2     TX            387
## 3     NY            311
## 4     VA            283
## 5     FL            282
## 6     IL            273
## 7     GA            212
## 8     OH            186
## 9     MA            182
## 10    PA            164
## 11    NJ            158
## 12    NC            137
## 13    CO            134
## 14    MD            131
## 15    WA            130
## 16    MI            126
## 17    AZ            100
## 18    UT             95
## 19    MN             88
## 20    TN             82
## 21    WI             79
## 22    IN             69
## 23    MO             59
## 24    AL             51
## 25    CT             50
## 26    OR             49
## 27    SC             48
## 28    OK             46
## 29    DC             43
## 30    KY             40
## 31    KS             38
## 32    LA             37
## 33    IA             28
## 34    NE             27
## 35    NV             26
## 36    NH             24
## 37    ID             17
## 38    DE             16
## 39    RI             16
## 40    ME             13
## 41    MS             12
## 42    ND             10
## 43    AR              9
## 44    HI              7
## 45    VT              6
## 46    NM              5
## 47    MT              4
## 48    SD              3
## 49    AK              2
## 50    WV              2
## 51    WY              2
## 52    PR              1
ggplot(data = inc5000State_df, aes(x=reorder(State, TotalCompanies) , y=TotalCompanies, fill=TotalCompanies)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black", width = 0.80) +  
      scale_fill_gradient(low="light green", high="dark green") + coord_flip() + 
      scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) + guides(fill=FALSE) +
      ggtitle("Distribution of Companies") + xlab("State") + ylab("Total Companies") 

ggsave("Figure1.png")
## Saving 7 x 5 in image
ggplot(data = inc5000State_df, aes(x=reorder(State, TotalCompanies) , y=TotalCompanies, fill=TotalCompanies)) +
      geom_point() +
      scale_fill_gradient(low="light green", high="dark green") + coord_flip() + 
      scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) + guides(fill=FALSE) +
      ggtitle("Distribution of Companies") + xlab("State") + ylab("Total Companies") 

ggsave("Figure11.png")
## Saving 7 x 5 in image
(2) Let’s 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 of average employment by industry for companies in this state (only use cases with full data (use R’s complete.cases() function). Your graph show show how variable the ranges are, and exlude outliers.
nrow(inc5000_df)
## [1] 5001
incComplete_df <- as.data.frame(inc5000_df %>% filter(complete.cases(.))) #only include complete cases
nrow(incComplete_df)
## [1] 4989
incCompleteNY_df = filter(incComplete_df, State == "NY")
incCompleteNY_df = select(incCompleteNY_df, matches("Name|Growth_Rate|Revenue|Industry|Employees|State"))
incCompleteNY_df = arrange(incCompleteNY_df, Industry)
nrow(incCompleteNY_df)
## [1] 311
print(incCompleteNY_df)
##                                             Name Growth_Rate   Revenue                     Industry Employees State
## 1                                       Sailthru       73.22 8.100e+06      Advertising & Marketing        79    NY
## 2                                   YellowHammer       67.40 1.800e+07      Advertising & Marketing        27    NY
## 3                                      Conductor       67.02 7.100e+06      Advertising & Marketing        89    NY
## 4                                       33Across       44.99 2.790e+07      Advertising & Marketing        75    NY
## 5                                     LiveIntent       44.85 6.900e+06      Advertising & Marketing        42    NY
## 6                                  Gravity Media       17.24 1.240e+07      Advertising & Marketing        15    NY
## 7                                            SET       15.28 2.370e+07      Advertising & Marketing        46    NY
## 8                                           Grok       10.77 9.400e+06      Advertising & Marketing        19    NY
## 9                                Carrot Creative       10.24 7.200e+06      Advertising & Marketing        45    NY
## 10                                     Largetail        9.10 3.700e+06      Advertising & Marketing        12    NY
## 11                                 LocalResponse        7.94 3.900e+06      Advertising & Marketing        25    NY
## 12                                  Driven Local        6.45 7.500e+06      Advertising & Marketing        28    NY
## 13                            Vector Media Group        6.30 2.100e+06      Advertising & Marketing        12    NY
## 14                                   Fingerpaint        5.55 9.500e+06      Advertising & Marketing        51    NY
## 15                         Launchpad Advertising        5.40 6.600e+06      Advertising & Marketing        40    NY
## 16                                     Optimatic        4.97 8.700e+06      Advertising & Marketing         8    NY
## 17                              Resolute Digital        4.26 7.100e+06      Advertising & Marketing        28    NY
## 18                           Dionysus Consulting        3.96 3.400e+06      Advertising & Marketing        22    NY
## 19                           Blue Fountain Media        3.85 1.420e+07      Advertising & Marketing       180    NY
## 20                           UpSurge Media Group        3.84 3.600e+06      Advertising & Marketing         2    NY
## 21                                Likeable Media        3.72 5.000e+06      Advertising & Marketing        65    NY
## 22                                      Sub Rosa        3.56 9.500e+06      Advertising & Marketing        28    NY
## 23                                      Trepoint        3.43 4.300e+06      Advertising & Marketing        15    NY
## 24                                 Madison Logic        3.14 1.490e+07      Advertising & Marketing        51    NY
## 25                                 Media6Degrees        2.82 3.670e+07      Advertising & Marketing        87    NY
## 26                            AdCorp Media Group        2.65 6.800e+06      Advertising & Marketing        38    NY
## 27                                        Droga5        2.54 6.730e+07      Advertising & Marketing       250    NY
## 28                               Enter:Marketing        2.47 6.500e+06      Advertising & Marketing        35    NY
## 29                                           MKG        2.27 2.090e+07      Advertising & Marketing        41    NY
## 30                                   React2Media        1.78 5.600e+06      Advertising & Marketing        15    NY
## 31                                         inVNT        1.67 2.550e+07      Advertising & Marketing        44    NY
## 32                      DiGennaro Communications        1.52 4.700e+06      Advertising & Marketing        32    NY
## 33                                          Rain        1.51 1.070e+07      Advertising & Marketing        74    NY
## 34                                      Sullivan        1.50 9.900e+06      Advertising & Marketing        63    NY
## 35                            Primary Wave Media        1.30 3.000e+06      Advertising & Marketing        15    NY
## 36                                  CreativeFeed        1.29 9.700e+06      Advertising & Marketing        32    NY
## 37                                       IOMedia        1.27 1.350e+07      Advertising & Marketing       133    NY
## 38                       LeadDog Marketing Group        1.23 3.290e+07      Advertising & Marketing       131    NY
## 39                               Taylor Creative        1.22 9.200e+06      Advertising & Marketing        35    NY
## 40                                    VHMnetwork        1.09 4.500e+06      Advertising & Marketing        10    NY
## 41                                 Team Epiphany        1.06 8.200e+06      Advertising & Marketing        37    NY
## 42                               Verge Marketing        1.04 4.000e+06      Advertising & Marketing        21    NY
## 43                        Juice Pharma Worldwide        1.04 5.380e+07      Advertising & Marketing       186    NY
## 44                              Modus Associates        0.99 2.300e+06      Advertising & Marketing         9    NY
## 45                                   Butler/Till        0.97 1.236e+08      Advertising & Marketing        73    NY
## 46                            Influence Graphics        0.86 4.100e+06      Advertising & Marketing        24    NY
## 47                                     Post Beam        0.84 5.900e+06      Advertising & Marketing        32    NY
## 48                                Motivators.com        0.62 1.320e+07      Advertising & Marketing        55    NY
## 49                                 Direct Agents        0.54 2.270e+07      Advertising & Marketing        47    NY
## 50                                   C2C Outdoor        0.53 2.770e+07      Advertising & Marketing        12    NY
## 51                  ePromos Promotional Products        0.49 2.840e+07      Advertising & Marketing       104    NY
## 52                                      Paradysz        0.49 4.100e+07      Advertising & Marketing       270    NY
## 53                                    SaveAround        0.46 6.900e+06      Advertising & Marketing        64    NY
## 54                                   McMurry/TMG        0.43 9.140e+07      Advertising & Marketing       269    NY
## 55                                      Makovsky        0.40 1.430e+07      Advertising & Marketing        55    NY
## 56                                        Affect        0.39 2.600e+06      Advertising & Marketing        18    NY
## 57                           Premium Productions        0.36 6.800e+06      Advertising & Marketing        16    NY
## 58                                     MSR Promo       16.30 2.400e+06 Business Products & Services         4    NY
## 59                                       Panjiva       13.77 4.000e+06 Business Products & Services        48    NY
## 60                      Manhattan Strategy Group        3.60 6.300e+06 Business Products & Services        30    NY
## 61                                Vcorp Services        2.17 6.300e+06 Business Products & Services        15    NY
## 62                                     KJT Group        1.68 7.200e+06 Business Products & Services        32    NY
## 63                               LDJ Productions        1.54 1.230e+07 Business Products & Services        12    NY
## 64                                           RVM        1.42 1.880e+07 Business Products & Services       106    NY
## 65                                     Leviathan        1.34 4.840e+07 Business Products & Services        11    NY
## 66                                  ReSource Pro        1.22 2.430e+07 Business Products & Services      1124    NY
## 67                                  WTP Advisors        1.16 1.600e+07 Business Products & Services        90    NY
## 68                                 SmartSign.com        1.07 2.530e+07 Business Products & Services        34    NY
## 69                                     Docutrend        0.82 8.200e+06 Business Products & Services        45    NY
## 70                                 Empire Office        0.66 3.496e+08 Business Products & Services       345    NY
## 71                                    NorthPoint        0.64 2.730e+07 Business Products & Services       144    NY
## 72                                      Fragomen        0.60 3.465e+08 Business Products & Services       404    NY
## 73                                    LinguaLinx        0.57 4.300e+06 Business Products & Services        32    NY
## 74                                  TransPerfect        0.55 3.413e+08 Business Products & Services      2218    NY
## 75                            The Atlantic Group        0.52 6.430e+07 Business Products & Services        51    NY
## 76                              Geneva Worldwide        0.50 7.400e+06 Business Products & Services        30    NY
## 77                    Sutherland Global Services        0.48 5.976e+08 Business Products & Services     32000    NY
## 78                                     Mimeo.com        0.46 8.770e+07 Business Products & Services       632    NY
## 79              Copier Fax Business Technologies        0.44 5.300e+06 Business Products & Services        27    NY
## 80                              Benefit Resource        0.41 1.330e+07 Business Products & Services        96    NY
## 81                                 Jackson Lewis        0.37 3.520e+08 Business Products & Services       690    NY
## 82                               McElroy Deutsch        0.36 1.165e+08 Business Products & Services       288    NY
## 83   SmartSource Computer & Audio Visual Rentals        0.35 5.730e+07 Business Products & Services       296    NY
## 84                                 Myriad Supply        1.19 2.290e+07            Computer Hardware        44    NY
## 85                                  Spicer Group        2.25 5.600e+06                 Construction        20    NY
## 86                               Durante Rentals        2.03 4.800e+06                 Construction        25    NY
## 87                                 DDS Companies        1.09 5.250e+07                 Construction       219    NY
## 88                               The Urban Group        0.86 5.700e+06                 Construction        24    NY
## 89   American Petroleum Equipment & Construction        0.46 1.040e+07                 Construction        68    NY
## 90              Colorspec Coatings International        0.36 3.300e+06                 Construction        10    NY
## 91                                  BeenVerified       84.43 1.370e+07 Consumer Products & Services        17    NY
## 92                                 Bustin Boards        9.92 4.000e+06 Consumer Products & Services        25    NY
## 93                           Happy Family Brands        8.70 6.250e+07 Consumer Products & Services        51    NY
## 94                               The Classy Home        6.43 2.800e+06 Consumer Products & Services        18    NY
## 95                                Digital Energy        5.79 1.230e+07 Consumer Products & Services        16    NY
## 96                                         Tarte        4.03 5.240e+07 Consumer Products & Services       100    NY
## 97                                  ArkNet Media        3.82 5.300e+06 Consumer Products & Services        20    NY
## 98                                   Tribeca Nik        2.27 4.700e+06 Consumer Products & Services         5    NY
## 99                                Society Awards        2.26 3.300e+06 Consumer Products & Services        10    NY
## 100                                  Sachin Babi        1.80 4.700e+06 Consumer Products & Services        23    NY
## 101                           Weiss & Associates        1.26 2.000e+06 Consumer Products & Services         9    NY
## 102                             Gates Automotive        1.07 6.900e+06 Consumer Products & Services        64    NY
## 103                              Home Clean Home        0.94 2.100e+06 Consumer Products & Services        55    NY
## 104                                Tully Rinckey        0.86 8.800e+06 Consumer Products & Services        87    NY
## 105                                Best Cleaners        0.84 4.800e+06 Consumer Products & Services        85    NY
## 106                         Catseye Pest Control        0.51 9.000e+06 Consumer Products & Services        62    NY
## 107                                         Coty        0.36 4.600e+09 Consumer Products & Services     10000    NY
## 108                               Rethink Autism       18.27 4.100e+06                    Education        22    NY
## 109                                 Private Prep        6.12 2.500e+06                    Education       100    NY
## 110                       Imagine Easy Solutions        4.45 3.600e+06                    Education        19    NY
## 111                            City Sounds of NY        2.92 2.000e+06                    Education        40    NY
## 112                                  CleanEdison        1.94 3.500e+06                    Education        25    NY
## 113                             Imagine Swimming        1.89 5.100e+06                    Education       100    NY
## 114                  School Choice International        1.24 2.800e+06                    Education        21    NY
## 115                                Dance With Me        1.01 4.000e+06                    Education        50    NY
## 116                            Bespoke Education        0.94 2.600e+06                    Education        70    NY
## 117                             Graduationsource        0.92 5.300e+06                    Education        55    NY
## 118                                ClassBook.com        0.73 9.600e+06                    Education        61    NY
## 119                                Gersh Academy        0.70 8.600e+06                    Education        51    NY
## 120                           New York Kids Club        0.56 1.250e+07                    Education       200    NY
## 121                                    Webucator        0.45 4.600e+06                    Education        24    NY
## 122                             SmartWatt Energy        7.54 3.880e+07                       Energy       137    NY
## 123                                        Ioxus        4.67 5.400e+06                       Energy        90    NY
## 124                      U.S. Energy Development        1.89 1.408e+08                       Energy       120    NY
## 125                 Precision Pipeline Solutions        1.39 3.120e+07                       Energy       294    NY
## 126                         Cedar Petrochemcials        1.31 2.037e+08                       Energy         5    NY
## 127                     Sam Schwartz Engineering        0.51 1.680e+07                  Engineering        94    NY
## 128                        Presentation Products        0.51 9.700e+06                  Engineering        29    NY
## 129                                DatapointLabs        0.46 2.500e+06                  Engineering        11    NY
## 130              Rand Engineering & Architecture        0.38 9.800e+06                  Engineering        80    NY
## 131 Environmental Products & Services of Vermont        0.81 4.510e+07       Environmental Services       250    NY
## 132               Creative Environment Solutions        0.62 5.300e+06       Environmental Services        60    NY
## 133                    Cinium Financial Services       53.65 5.900e+06           Financial Services        32    NY
## 134                                  RCS Capital        9.19 2.875e+08           Financial Services       198    NY
## 135                           ForwardThink Group        7.01 2.170e+07           Financial Services        70    NY
## 136                                       OnDeck        6.98 3.670e+07           Financial Services       153    NY
## 137                            Merchant Industry        6.42 2.240e+07           Financial Services       102    NY
## 138                                     Payoneer        5.00 4.040e+07           Financial Services       207    NY
## 139               Reliance Star Payment Services        1.97 2.000e+06           Financial Services        14    NY
## 140           Charter School Business Management        1.76 3.800e+06           Financial Services        33    NY
## 141                                     ConServe        1.14 5.270e+07           Financial Services       483    NY
## 142                              Gerstein Fisher        0.84 9.700e+06           Financial Services        35    NY
## 143       American Portfolios Financial Services        0.77 1.170e+08           Financial Services        81    NY
## 144                       Capital Access Network        0.49 1.516e+08           Financial Services       425    NY
## 145                         GTM Payroll Services        0.40 6.700e+06           Financial Services        43    NY
## 146                         Rockhedge Herb Farms        8.70 5.100e+06              Food & Beverage        56    NY
## 147                                Peeled Snacks        5.94 5.800e+06              Food & Beverage        14    NY
## 148                                  Servomation        2.03 5.500e+06              Food & Beverage        41    NY
## 149                                  Cafe Grumpy        1.46 2.200e+06              Food & Beverage        30    NY
## 150                    Adventure in Food Trading        1.32 2.600e+06              Food & Beverage        12    NY
## 151                              Magnolia Bakery        0.88 2.360e+07              Food & Beverage       383    NY
## 152                                    SweetRiot        0.86 2.000e+06              Food & Beverage         5    NY
## 153                          Bogota Latin Bistro        0.48 3.800e+06              Food & Beverage        63    NY
## 154                              Greyston Bakery        0.42 1.010e+07              Food & Beverage        84    NY
## 155                        Cipher Tech Solutions        2.69 2.700e+06          Government Services        17    NY
## 156                               Forward Health       11.07 1.050e+07                       Health         6    NY
## 157                             Armadale Capital        7.27 3.600e+06                       Health         2    NY
## 158                         Quality In Real Time        6.94 2.900e+06                       Health       121    NY
## 159                    Professional Data Systems        2.76 6.300e+06                       Health        37    NY
## 160                                PM Pediatrics        1.70 1.410e+07                       Health       181    NY
## 161                             The Fortus Group        1.39 6.200e+06                       Health        50    NY
## 162                  Central Park West Dentistry        1.39 3.100e+06                       Health        20    NY
## 163                               Treo Solutions        1.31 2.760e+07                       Health       166    NY
## 164                                      Onco360        1.24 1.122e+08                       Health        67    NY
## 165                       eTransMedia Technology        0.72 2.590e+07                       Health       298    NY
## 166                       Spear Physical Therapy        0.67 5.200e+06                       Health        40    NY
## 167                                Nutricap Labs        0.67 3.000e+07                       Health        45    NY
## 168                                 EquipSystems        0.48 3.000e+06                       Health        31    NY
## 169                                     Ivy Exec       14.01 2.200e+06              Human Resources        30    NY
## 170                                BarkerGilmore        4.22 2.100e+06              Human Resources        12    NY
## 171                              Oliver Staffing        2.78 4.600e+06              Human Resources         7    NY
## 172                         Sterling Infosystems        2.66 2.149e+08              Human Resources      2081    NY
## 173                             Andiamo Partners        2.46 6.200e+06              Human Resources         8    NY
## 174                                   BountyJobs        1.56 3.080e+07              Human Resources        56    NY
## 175                           Pride Technologies        1.13 2.310e+08              Human Resources      1000    NY
## 176                       FSO Onsite Outsourcing        1.05 5.530e+07              Human Resources      1134    NY
## 177                              Atrium Staffing        1.03 9.700e+07              Human Resources       107    NY
## 178                                     HR Works        0.93 4.300e+06              Human Resources        53    NY
## 179                Infinity Consulting Solutions        0.79 3.570e+07              Human Resources       325    NY
## 180                        Global Warranty Group        2.78 2.810e+07                    Insurance        50    NY
## 181                         DurAmerica Brokerage        0.43 2.700e+06                    Insurance        15    NY
## 182                           Novisync Solutions       19.28 7.500e+06                  IT Services       119    NY
## 183                          Salzinger & Company        5.53 3.900e+06                  IT Services        15    NY
## 184                 Envisage Information Systems        5.04 1.700e+07                  IT Services       142    NY
## 185                                       Enstoa        4.11 7.000e+06                  IT Services        40    NY
## 186                          Systems Made Simple        3.94 1.671e+08                  IT Services       382    NY
## 187                                    Usablenet        3.52 5.900e+07                  IT Services       295    NY
## 188                                     InRhythm        3.47 3.200e+06                  IT Services        27    NY
## 189                                     BlueWolf        2.38 9.040e+07                  IT Services       500    NY
## 190     New York Technology Partners - Rochester        2.37 3.200e+06                  IT Services        23    NY
## 191                     Deep Blue Communications        2.19 5.600e+06                  IT Services        47    NY
## 192                                nfrastructure        2.00 5.320e+07                  IT Services       237    NY
## 193                                  WorkCompEDI        1.66 2.900e+06                  IT Services        13    NY
## 194                           Shinetech Software        1.48 1.200e+07                  IT Services       300    NY
## 195                  Systems Management/Planning        1.45 5.200e+07                  IT Services        52    NY
## 196                                       QueBIT        1.42 1.470e+07                  IT Services        46    NY
## 197                              Primary Support        1.36 2.300e+06                  IT Services        14    NY
## 198                                     TekScape        1.32 1.360e+07                  IT Services        26    NY
## 199                                           D4        1.22 1.430e+07                  IT Services       125    NY
## 200                             Flexible Systems        1.13 2.960e+07                  IT Services        95    NY
## 201                                       Linium        1.11 4.590e+07                  IT Services       322    NY
## 202                               Sriven Systems        0.98 2.530e+07                  IT Services       210    NY
## 203                              Mitchell/Martin        0.92 1.453e+08                  IT Services      1000    NY
## 204                      Alphaserve Technologies        0.92 1.640e+07                  IT Services        80    NY
## 205                          Stemp Systems Group       19.37 6.800e+06                  IT Services        39    NY
## 206                       Proactive Technologies        0.86 4.000e+06                  IT Services        24    NY
## 207                                     Infusion        0.84 6.790e+07                  IT Services       432    NY
## 208                Integrated Systems Management        0.83 4.600e+06                  IT Services       144    NY
## 209                            Liquid Technology        0.81 1.000e+07                  IT Services        33    NY
## 210                 Eminent Technology Solutions        0.80 6.300e+06                  IT Services        48    NY
## 211                              LISS Consulting        0.79 2.400e+06                  IT Services        18    NY
## 212                                     Net@Work        0.72 2.930e+07                  IT Services       156    NY
## 213                                         Sinu        0.70 3.000e+06                  IT Services        25    NY
## 214                                         BUMI        0.65 2.300e+06                  IT Services         8    NY
## 215                Computer Resources of America        0.59 7.700e+06                  IT Services        47    NY
## 216                     KJ Technology Consulting        0.51 4.000e+06                  IT Services        13    NY
## 217                                       Tabush        0.48 3.900e+06                  IT Services        23    NY
## 218                              Brite Computers        0.47 1.990e+07                  IT Services        54    NY
## 219                                 QED National        0.47 6.700e+06                  IT Services        89    NY
## 220                                      Inergex        0.47 1.740e+07                  IT Services       140    NY
## 221                                Westcon Group        0.44 3.800e+09                  IT Services      3000    NY
## 222                                      Mycroft        0.43 2.640e+07                  IT Services       275    NY
## 223                              The Lloyd Group        0.42 9.900e+06                  IT Services        73    NY
## 224                     Documentation Strategies        0.41 2.300e+06                  IT Services        25    NY
## 225                     Direct Transport Systems        4.15 2.800e+06   Logistics & Transportation         1    NY
## 226                              LJM Consultants        2.43 4.200e+06   Logistics & Transportation        22    NY
## 227                            Logistic Dynamics        1.18 3.960e+07   Logistics & Transportation        25    NY
## 228                 Express Air Freight Unlmited        0.38 2.860e+07   Logistics & Transportation        70    NY
## 229                 Ultraflex Power Technologies       14.54 2.200e+06                Manufacturing        12    NY
## 230                                     Adafruit        3.75 8.700e+06                Manufacturing        40    NY
## 231                           ALAC International        3.42 5.650e+07                Manufacturing        11    NY
## 232                      Signature Systems Group        1.81 8.100e+07                Manufacturing        77    NY
## 233                             Bear Metal Works        1.48 2.400e+06                Manufacturing        13    NY
## 234                                Ryan Printing        1.30 7.300e+06                Manufacturing        26    NY
## 235                         Access Display Group        1.02 4.100e+06                Manufacturing        22    NY
## 236                                Liberty Pumps        0.84 6.080e+07                Manufacturing       132    NY
## 237                              Optimax Systems        0.76 2.010e+07                Manufacturing       200    NY
## 238                                  JR Products        0.62 4.900e+06                Manufacturing        30    NY
## 239                                     NiCoForm        0.59 2.100e+06                Manufacturing        16    NY
## 240                                Aluf Plastics        0.40 1.029e+08                Manufacturing       307    NY
## 241                               Buffalo Filter        0.37 1.500e+07                Manufacturing        67    NY
## 242                                   Refinery29       23.01 1.660e+07                        Media        99    NY
## 243                                   NUE Agency       16.04 4.500e+06                        Media         4    NY
## 244                                 RosettaBooks       15.49 3.200e+06                        Media         7    NY
## 245                             Surface Magazine        8.63 3.900e+06                        Media        14    NY
## 246                                   Touchstorm        6.84 6.700e+06                        Media        46    NY
## 247                        Thrillist Media Group        6.52 5.250e+07                        Media       200    NY
## 248                                   Livestream        6.13 1.890e+07                        Media       146    NY
## 249                                 Curbed Media        4.06 5.100e+06                        Media        45    NY
## 250                            MyDailyMoment.com        0.96 5.900e+06                        Media        16    NY
## 251                              Everyday Health        0.62 1.464e+08                        Media       602    NY
## 252                               Blue Telescope        0.52 3.400e+06                        Media         9    NY
## 253                               The Ruby Group        5.57 1.100e+07                  Real Estate        15    NY
## 254                                    Hipercept        5.23 4.200e+06                  Real Estate        30    NY
## 255                                   1st Equity        1.38 2.100e+06                  Real Estate         7    NY
## 256                         Select Office Suites        0.52 7.600e+06                  Real Estate        21    NY
## 257                     Renegade Furniture Group       29.26 9.800e+06                       Retail        17    NY
## 258                                  BulbAmerica        6.16 6.300e+06                       Retail        22    NY
## 259                              Rebecca Minkoff        4.75 5.890e+07                       Retail        75    NY
## 260                                     Berricle        3.34 2.200e+06                       Retail        11    NY
## 261                              Decorplanet.com        3.25 1.380e+07                       Retail        61    NY
## 262                            Dynomighty Design        2.74 4.000e+06                       Retail        12    NY
## 263                                   Gaffos.com        2.58 4.400e+06                       Retail        15    NY
## 264                         Medical Supply Depot        1.89 2.600e+06                       Retail         3    NY
## 265                            Christmas Central        1.69 1.650e+07                       Retail        75    NY
## 266                      Marvin Traub Associates        1.42 3.800e+06                       Retail        12    NY
## 267                                    Nasty Pig        1.09 2.000e+06                       Retail        10    NY
## 268                               MyOTCStore.com        1.06 3.140e+07                       Retail        15    NY
## 269                                   ItsHot.com        0.57 5.700e+06                       Retail         9    NY
## 270                                  PlayScripts        0.43 2.600e+06                       Retail        10    NY
## 271                         IntraLogic Solutions        1.59 3.700e+06                     Security        25    NY
## 272             Sentry Communications & Security        0.48 6.000e+06                     Security        40    NY
## 273                               Arrow Security        0.44 1.400e+07                     Security       450    NY
## 274               Life Safety Engineered Systems        0.42 7.100e+06                     Security        25    NY
## 275                                     Impelsys        2.94 1.290e+07                     Software       220    NY
## 276                                     ModiFace        2.55 2.100e+06                     Software        25    NY
## 277                                 Globo Mobile        1.67 4.500e+06                     Software       320    NY
## 278                          Celerant Technology        1.60 1.820e+07                     Software        80    NY
## 279                                 SportsSignup        1.25 3.300e+06                     Software        21    NY
## 280                                      DataArt        1.14 3.070e+07                     Software       800    NY
## 281                         Cvision Technologies        0.63 5.200e+06                     Software        28    NY
## 282                                     Edulence        0.62 2.000e+06                     Software        15    NY
## 283                             Cyrus Innovation        0.56 5.900e+06                     Software        46    NY
## 284                                      Kitware        0.55 2.130e+07                     Software       110    NY
## 285                                     OpenLink        0.52 3.043e+08                     Software      1271    NY
## 286                                      Numerix        0.48 5.640e+07                     Software       198    NY
## 287                                  Transfinder        0.47 7.800e+06                     Software        63    NY
## 288                             Quantum Networks       29.44 1.150e+07           Telecommunications        28    NY
## 289                          Technical Solutions       15.85 1.630e+07           Telecommunications       213    NY
## 290                   Odyssey Telecommunications       11.40 3.300e+06           Telecommunications         6    NY
## 291                          MASS Communications        9.33 9.800e+06           Telecommunications        25    NY
## 292                             Integra Networks        8.83 1.660e+07           Telecommunications        31    NY
## 293                                 MaeTec Power        2.03 1.010e+07           Telecommunications        22    NY
## 294                         Soleo Communications        1.40 1.410e+07           Telecommunications        85    NY
## 295               Advantage Communications Group        1.38 5.600e+06           Telecommunications        15    NY
## 296                             Stage 2 Networks        1.27 9.200e+06           Telecommunications        20    NY
## 297                                         Telx        1.18 2.143e+08           Telecommunications       316    NY
## 298                           Fibertech Networks        1.13 1.423e+08           Telecommunications       250    NY
## 299                            5Linx Enterprises        1.12 1.036e+08           Telecommunications       268    NY
## 300              Finger Lakes Technologies Group        0.70 2.310e+07           Telecommunications       105    NY
## 301                                Send Word Now        0.67 1.660e+07           Telecommunications        59    NY
## 302           Business Communications Management        0.62 1.090e+07           Telecommunications        21    NY
## 303                            BPA International        0.53 5.400e+06           Telecommunications       139    NY
## 304                                      VarData        0.45 1.480e+07           Telecommunications        18    NY
## 305                                  Regal Wings       25.13 1.540e+07         Travel & Hospitality        42    NY
## 306                      In the Know Experiences        5.39 4.300e+06         Travel & Hospitality         6    NY
## 307                       Liberty Jet Management        1.73 8.900e+06         Travel & Hospitality        61    NY
## 308                                 Xtreme Trips        0.76 6.700e+06         Travel & Hospitality        30    NY
## 309                    Denihan Hospitality Group        0.71 2.808e+08         Travel & Hospitality      2280    NY
## 310                         Ovation Travel Group        0.67 5.860e+07         Travel & Hospitality       509    NY
## 311                                  TravelClick        0.43 2.571e+08         Travel & Hospitality       906    NY
incCompleteNY_Group_df = as.data.frame(incCompleteNY_df %>% group_by(Industry) 
                              %>% summarise( TotalEmployees = sum(Employees), TotalCompanies = n()))
incCompleteNY_Group_df = arrange(incCompleteNY_Group_df, desc(TotalEmployees))
print(incCompleteNY_Group_df)
##                        Industry TotalEmployees TotalCompanies
## 1  Business Products & Services          38804             26
## 2  Consumer Products & Services          10647             17
## 3                   IT Services           8776             43
## 4               Human Resources           4813             11
## 5          Travel & Hospitality           3834              7
## 6       Advertising & Marketing           3331             57
## 7                      Software           3197             13
## 8            Financial Services           1876             13
## 9            Telecommunications           1621             17
## 10                        Media           1188             11
## 11                       Health           1064             13
## 12                Manufacturing            953             13
## 13                    Education            838             14
## 14              Food & Beverage            688              9
## 15                       Energy            646              5
## 16                     Security            540              4
## 17                 Construction            366              6
## 18                       Retail            347             14
## 19       Environmental Services            310              2
## 20                  Engineering            214              4
## 21   Logistics & Transportation            118              4
## 22                  Real Estate             73              4
## 23                    Insurance             65              2
## 24            Computer Hardware             44              1
## 25          Government Services             17              1
calcAverage = function(employees, companies) {
  round(employees/companies, 2)
}

incCompleteNY_Group_df = mutate(incCompleteNY_Group_df, AvgEmployees=calcAverage(TotalEmployees, TotalCompanies))
print (incCompleteNY_Group_df)
##                        Industry TotalEmployees TotalCompanies AvgEmployees
## 1  Business Products & Services          38804             26      1492.46
## 2  Consumer Products & Services          10647             17       626.29
## 3                   IT Services           8776             43       204.09
## 4               Human Resources           4813             11       437.55
## 5          Travel & Hospitality           3834              7       547.71
## 6       Advertising & Marketing           3331             57        58.44
## 7                      Software           3197             13       245.92
## 8            Financial Services           1876             13       144.31
## 9            Telecommunications           1621             17        95.35
## 10                        Media           1188             11       108.00
## 11                       Health           1064             13        81.85
## 12                Manufacturing            953             13        73.31
## 13                    Education            838             14        59.86
## 14              Food & Beverage            688              9        76.44
## 15                       Energy            646              5       129.20
## 16                     Security            540              4       135.00
## 17                 Construction            366              6        61.00
## 18                       Retail            347             14        24.79
## 19       Environmental Services            310              2       155.00
## 20                  Engineering            214              4        53.50
## 21   Logistics & Transportation            118              4        29.50
## 22                  Real Estate             73              4        18.25
## 23                    Insurance             65              2        32.50
## 24            Computer Hardware             44              1        44.00
## 25          Government Services             17              1        17.00
ggplot(data = incCompleteNY_Group_df, aes(x=reorder(Industry, AvgEmployees) , y=AvgEmployees, fill=AvgEmployees)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black", width = 0.80) +  
      scale_fill_gradient(low="light blue", high="dark blue") +
      scale_y_continuous(breaks = scales::pretty_breaks(n = 20)) + guides(fill=FALSE) +
      theme(axis.text.x=element_text(angle=90,hjust=1)) +
      ggtitle("Average Employment by Industry in NY") + xlab("Industry") + ylab("Average Employment") 

ggsave("Figure2.png")
## Saving 7 x 5 in image
(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.
incComplete_df = arrange(incComplete_df, Industry)
nrow(incComplete_df)
## [1] 4989
incComplete_Group_df = as.data.frame(incComplete_df %>% group_by(Industry) 
                       %>% summarise( TotalEmployees = sum(Employees), TotalRevenue = sum(Revenue), TotalCompanies = n()))
print(incComplete_Group_df)
##                        Industry TotalEmployees TotalRevenue TotalCompanies
## 1       Advertising & Marketing          39731   7785000000            471
## 2  Business Products & Services         117357  26345900000            480
## 3             Computer Hardware           9714  11885700000             44
## 4                  Construction          29099  13174300000            187
## 5  Consumer Products & Services          45464  14956400000            203
## 6                     Education           7685   1139300000             83
## 7                        Energy          26437  13771600000            109
## 8                   Engineering          20435   2532500000             74
## 9        Environmental Services          10155   2638800000             51
## 10           Financial Services          47693  13150900000            260
## 11              Food & Beverage          65911  12812500000            129
## 12          Government Services          26185   6009100000            202
## 13                       Health          82430  17860100000            354
## 14              Human Resources         226980   9246100000            196
## 15                    Insurance           7339   2337900000             50
## 16                  IT Services         102788  20525000000            732
## 17   Logistics & Transportation          39994  14837800000            154
## 18                Manufacturing          43942  12603600000            255
## 19                        Media           9532   1742400000             54
## 20                  Real Estate          18893   2956800000             95
## 21                       Retail          37068  10257400000            203
## 22                     Security          41059   3812800000             73
## 23                     Software          51262   8134600000            341
## 24           Telecommunications          30842   7287900000            127
## 25         Travel & Hospitality          23035   2931600000             62
calcRevenuePerEmployee = function(TotalRevenue, TotalEmployees) {
  return (round(TotalRevenue/(TotalEmployees*1000), 2))
}

incComplete_Group_df = mutate(incComplete_Group_df, RevenuePerEmployee=calcRevenuePerEmployee(TotalRevenue, TotalEmployees))
incComplete_Group_df = arrange(incComplete_Group_df, desc(RevenuePerEmployee))
print (incComplete_Group_df)
##                        Industry TotalEmployees TotalRevenue TotalCompanies RevenuePerEmployee
## 1             Computer Hardware           9714  11885700000             44            1223.56
## 2                        Energy          26437  13771600000            109             520.92
## 3                  Construction          29099  13174300000            187             452.74
## 4    Logistics & Transportation          39994  14837800000            154             371.00
## 5  Consumer Products & Services          45464  14956400000            203             328.97
## 6                     Insurance           7339   2337900000             50             318.56
## 7                 Manufacturing          43942  12603600000            255             286.82
## 8                        Retail          37068  10257400000            203             276.72
## 9            Financial Services          47693  13150900000            260             275.74
## 10       Environmental Services          10155   2638800000             51             259.85
## 11           Telecommunications          30842   7287900000            127             236.30
## 12          Government Services          26185   6009100000            202             229.49
## 13 Business Products & Services         117357  26345900000            480             224.49
## 14                       Health          82430  17860100000            354             216.67
## 15                  IT Services         102788  20525000000            732             199.68
## 16      Advertising & Marketing          39731   7785000000            471             195.94
## 17              Food & Beverage          65911  12812500000            129             194.39
## 18                        Media           9532   1742400000             54             182.79
## 19                     Software          51262   8134600000            341             158.69
## 20                  Real Estate          18893   2956800000             95             156.50
## 21                    Education           7685   1139300000             83             148.25
## 22         Travel & Hospitality          23035   2931600000             62             127.27
## 23                  Engineering          20435   2532500000             74             123.93
## 24                     Security          41059   3812800000             73              92.86
## 25              Human Resources         226980   9246100000            196              40.74
ggplot(data = incComplete_Group_df, aes(x=reorder(Industry, RevenuePerEmployee) , 
                                        y=RevenuePerEmployee, fill=RevenuePerEmployee)) +
      geom_bar(stat="identity", position=position_dodge(), colour="black", width = 0.80) +  
      scale_fill_gradient(low="purple", high="purple4") + 
      scale_y_continuous(labels=scales::dollar, breaks = scales::pretty_breaks(n = 10)) + guides(fill=FALSE) +
      theme(axis.text.x=element_text(angle=90,hjust=1)) +
      ggtitle("Revenue Per Employee for Industries") + xlab("Industry") + ylab("Revenue Per Employee (Thousands)") 

ggsave("Figure3.png")
## Saving 7 x 5 in image