The purpose of this project is to visualize the usefulness of R within Data Analysis!

We will be using data that describes the life expectancy of the world based on variables including the continents, and life expectancy.

Lets Install R, Load our Data from gapminder into the sesssion for use, Load the data into the environment, and look at a summary of it.

install.packages("gapminder")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(gapminder)
data("gapminder")
summary(gapminder)
##         country        continent        year         lifeExp     
##  Afghanistan:  12   Africa  :624   Min.   :1952   Min.   :23.60  
##  Albania    :  12   Americas:300   1st Qu.:1966   1st Qu.:48.20  
##  Algeria    :  12   Asia    :396   Median :1980   Median :60.71  
##  Angola     :  12   Europe  :360   Mean   :1980   Mean   :59.47  
##  Argentina  :  12   Oceania : 24   3rd Qu.:1993   3rd Qu.:70.85  
##  Australia  :  12                  Max.   :2007   Max.   :82.60  
##  (Other)    :1632                                                
##       pop              gdpPercap       
##  Min.   :6.001e+04   Min.   :   241.2  
##  1st Qu.:2.794e+06   1st Qu.:  1202.1  
##  Median :7.024e+06   Median :  3531.8  
##  Mean   :2.960e+07   Mean   :  7215.3  
##  3rd Qu.:1.959e+07   3rd Qu.:  9325.5  
##  Max.   :1.319e+09   Max.   :113523.1  
## 

Lets observe the top and bottom ends of our data

head(gapminder)
## # A tibble: 6 × 6
##   country     continent  year lifeExp      pop gdpPercap
##   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Afghanistan Asia       1952    28.8  8425333      779.
## 2 Afghanistan Asia       1957    30.3  9240934      821.
## 3 Afghanistan Asia       1962    32.0 10267083      853.
## 4 Afghanistan Asia       1967    34.0 11537966      836.
## 5 Afghanistan Asia       1972    36.1 13079460      740.
## 6 Afghanistan Asia       1977    38.4 14880372      786.
tail(gapminder)
## # A tibble: 6 × 6
##   country  continent  year lifeExp      pop gdpPercap
##   <fct>    <fct>     <int>   <dbl>    <int>     <dbl>
## 1 Zimbabwe Africa     1982    60.4  7636524      789.
## 2 Zimbabwe Africa     1987    62.4  9216418      706.
## 3 Zimbabwe Africa     1992    60.4 10704340      693.
## 4 Zimbabwe Africa     1997    46.8 11404948      792.
## 5 Zimbabwe Africa     2002    40.0 11926563      672.
## 6 Zimbabwe Africa     2007    43.5 12311143      470.

Now I’ll find the mean for GDP per capita (gdpPercap) and assign it to a variable

mean(gapminder$gdpPercap)
## [1] 7215.327
x<-(gapminder$gdpPercap)
x
##    [1]    779.4453    820.8530    853.1007    836.1971    739.9811    786.1134
##    [7]    978.0114    852.3959    649.3414    635.3414    726.7341    974.5803
##   [13]   1601.0561   1942.2842   2312.8890   2760.1969   3313.4222   3533.0039
##   [19]   3630.8807   3738.9327   2497.4379   3193.0546   4604.2117   5937.0295
##   [25]   2449.0082   3013.9760   2550.8169   3246.9918   4182.6638   4910.4168
##   [31]   5745.1602   5681.3585   5023.2166   4797.2951   5288.0404   6223.3675
##   [37]   3520.6103   3827.9405   4269.2767   5522.7764   5473.2880   3008.6474
##   [43]   2756.9537   2430.2083   2627.8457   2277.1409   2773.2873   4797.2313
##   [49]   5911.3151   6856.8562   7133.1660   8052.9530   9443.0385  10079.0267
##   [55]   8997.8974   9139.6714   9308.4187  10967.2820   8797.6407  12779.3796
##   [61]  10039.5956  10949.6496  12217.2269  14526.1246  16788.6295  18334.1975
##   [67]  19477.0093  21888.8890  23424.7668  26997.9366  30687.7547  34435.3674
##   [73]   6137.0765   8842.5980  10750.7211  12834.6024  16661.6256  19749.4223
##   [79]  21597.0836  23687.8261  27042.0187  29095.9207  32417.6077  36126.4927
##   [85]   9867.0848  11635.7995  12753.2751  14804.6727  18268.6584  19340.1020
##   [91]  19211.1473  18524.0241  19035.5792  20292.0168  23403.5593  29796.0483
##   [97]    684.2442    661.6375    686.3416    721.1861    630.2336    659.8772
##  [103]    676.9819    751.9794    837.8102    972.7700   1136.3904   1391.2538
##  [109]   8343.1051   9714.9606  10991.2068  13149.0412  16672.1436  19117.9745
##  [115]  20979.8459  22525.5631  25575.5707  27561.1966  30485.8838  33692.6051
##  [121]   1062.7522    959.6011    949.4991   1035.8314   1085.7969   1029.1613
##  [127]   1277.8976   1225.8560   1191.2077   1232.9753   1372.8779   1441.2849
##  [133]   2677.3263   2127.6863   2180.9725   2586.8861   2980.3313   3548.0978
##  [139]   3156.5105   2753.6915   2961.6997   3326.1432   3413.2627   3822.1371
##  [145]    973.5332   1353.9892   1709.6837   2172.3524   2860.1698   3528.4813
##  [151]   4126.6132   4314.1148   2546.7814   4766.3559   6018.9752   7446.2988
##  [157]    851.2411    918.2325    983.6540   1214.7093   2263.6111   3214.8578
##  [163]   4551.1421   6205.8839   7954.1116   8647.1423  11003.6051  12569.8518
##  [169]   2108.9444   2487.3660   3336.5858   3429.8644   4985.7115   6660.1187
##  [175]   7030.8359   7807.0958   6950.2830   7957.9808   8131.2128   9065.8008
##  [181]   2444.2866   3008.6707   4254.3378   5577.0028   6597.4944   7612.2404
##  [187]   8224.1916   8239.8548   6302.6234   5970.3888   7696.7777  10680.7928
##  [193]    543.2552    617.1835    722.5120    794.8266    854.7360    743.3870
##  [199]    807.1986    912.0631    931.7528    946.2950   1037.6452   1217.0330
##  [205]    339.2965    379.5646    355.2032    412.9775    464.0995    556.1033
##  [211]    559.6032    621.8188    631.6999    463.1151    446.4035    430.0707
##  [217]    368.4693    434.0383    496.9136    523.4323    421.6240    524.9722
##  [223]    624.4755    683.8956    682.3032    734.2852    896.2260   1713.7787
##  [229]   1172.6677   1313.0481   1399.6074   1508.4531   1684.1465   1783.4329
##  [235]   2367.9833   2602.6642   1793.1633   1694.3375   1934.0114   2042.0952
##  [241]  11367.1611  12489.9501  13462.4855  16076.5880  18970.5709  22090.8831
##  [247]  22898.7921  26626.5150  26342.8843  28954.9259  33328.9651  36319.2350
##  [253]   1071.3107   1190.8443   1193.0688   1136.0566   1070.0133   1109.3743
##  [259]    956.7530    844.8764    747.9055    740.5063    738.6906    706.0165
##  [265]   1178.6659   1308.4956   1389.8176   1196.8106   1104.1040   1133.9850
##  [271]    797.9081    952.3861   1058.0643   1004.9614   1156.1819   1704.0637
##  [277]   3939.9788   4315.6227   4519.0943   5106.6543   5494.0244   4756.7638
##  [283]   5095.6657   5547.0638   7596.1260  10118.0532  10778.7838  13171.6388
##  [289]    400.4486    575.9870    487.6740    612.7057    676.9001    741.2375
##  [295]    962.4214   1378.9040   1655.7842   2289.2341   3119.2809   4959.1149
##  [301]   2144.1151   2323.8056   2492.3511   2678.7298   3264.6600   3815.8079
##  [307]   4397.5757   4903.2191   5444.6486   6117.3617   5755.2600   7006.5804
##  [313]   1102.9909   1211.1485   1406.6483   1876.0296   1937.5777   1172.6030
##  [319]   1267.1001   1315.9808   1246.9074   1173.6182   1075.8116    986.1479
##  [325]    780.5423    905.8602    896.3146    861.5932    904.8961    795.7573
##  [331]    673.7478    672.7748    457.7192    312.1884    241.1659    277.5519
##  [337]   2125.6214   2315.0566   2464.7832   2677.9396   3213.1527   3259.1790
##  [343]   4879.5075   4201.1949   4016.2395   3484.1644   3484.0620   3632.5578
##  [349]   2627.0095   2990.0108   3460.9370   4161.7278   5118.1469   5926.8770
##  [355]   5262.7348   5629.9153   6160.4163   6677.0453   7723.4472   9645.0614
##  [361]   1388.5947   1500.8959   1728.8694   2052.0505   2378.2011   2517.7365
##  [367]   2602.7102   2156.9561   1648.0738   1786.2654   1648.8008   1544.7501
##  [373]   3119.2365   4338.2316   5477.8900   6960.2979   9164.0901  11305.3852
##  [379]  13221.8218  13822.5839   8447.7949   9875.6045  11628.3890  14619.2227
##  [385]   5586.5388   6092.1744   5180.7559   5690.2680   5305.4453   6380.4950
##  [391]   7316.9181   7532.9248   5592.8440   5431.9904   6340.6467   8948.1029
##  [397]   6876.1403   8256.3439  10136.8671  11399.4449  13108.4536  14800.1606
##  [403]  15377.2285  16310.4434  14297.0212  16048.5142  17596.2102  22833.3085
##  [409]   9692.3852  11099.6593  13583.3135  15937.2112  18866.2072  20422.9015
##  [415]  21688.0405  25116.1758  26406.7399  29804.3457  32166.5001  35278.4187
##  [421]   2669.5295   2864.9691   3020.9893   3020.0505   3694.2124   3081.7610
##  [427]   2879.4681   2880.1026   2377.1562   1895.0170   1908.2609   2082.4816
##  [433]   1397.7171   1544.4030   1662.1374   1653.7230   2189.8745   2681.9889
##  [439]   2861.0924   2899.8422   3044.2142   3614.1013   4563.8082   6025.3748
##  [445]   3522.1107   3780.5467   4086.1141   4579.0742   5280.9947   6679.6233
##  [451]   7213.7913   6481.7770   7103.7026   7429.4559   5773.0445   6873.2623
##  [457]   1418.8224   1458.9153   1693.3359   1814.8807   2024.0081   2785.4936
##  [463]   3503.7296   3885.4607   3794.7552   4173.1818   4754.6044   5581.1810
##  [469]   3048.3029   3421.5232   3776.8036   4358.5954   4520.2460   5138.9224
##  [475]   4098.3442   4140.4421   4444.2317   5154.8255   5351.5687   5728.3535
##  [481]    375.6431    426.0964    582.8420    915.5960    672.4123    958.5668
##  [487]    927.8253    966.8968   1132.0550   2814.4808   7703.4959  12154.0897
##  [493]    328.9406    344.1619    380.9958    468.7950    514.3242    505.7538
##  [499]    524.8758    521.1341    582.8585    913.4708    765.3500    641.3695
##  [505]    362.1463    378.9042    419.4564    516.1186    566.2439    556.8084
##  [511]    577.8607    573.7413    421.3535    515.8894    530.0535    690.8056
##  [517]   6424.5191   7545.4154   9371.8426  10921.6363  14358.8759  15605.4228
##  [523]  18533.1576  21141.0122  20647.1650  23723.9502  28204.5906  33207.0844
##  [529]   7029.8093   8662.8349  10560.4855  12999.9177  16107.1917  18292.6351
##  [535]  20293.8975  22066.4421  24703.7961  25889.7849  28926.0323  30470.0167
##  [541]   4293.4765   4976.1981   6631.4592   8358.7620  11401.9484  21745.5733
##  [547]  15113.3619  11864.4084  13522.1575  14722.8419  12521.7139  13206.4845
##  [553]    485.2307    520.9267    599.6503    734.7829    756.0868    884.7553
##  [559]    835.8096    611.6589    665.6244    653.7302    660.5856    752.7497
##  [565]   7144.1144  10187.8267  12902.4629  14745.6256  18016.1803  20512.9212
##  [571]  22031.5327  24639.1857  26505.3032  27788.8842  30035.8020  32170.3744
##  [577]    911.2989   1043.5615   1190.0411   1125.6972   1178.2237    993.2240
##  [583]    876.0326    847.0061    925.0602   1005.2458   1111.9846   1327.6089
##  [589]   3530.6901   4916.2999   6017.1907   8513.0970  12724.8296  14195.5243
##  [595]  15268.4209  16120.5284  17541.4963  18747.6981  22514.2548  27538.4119
##  [601]   2428.2378   2617.1560   2750.3644   3242.5311   4031.4083   4879.9927
##  [607]   4820.4948   4246.4860   4439.4508   4684.3138   4858.3475   5186.0500
##  [613]    510.1965    576.2670    686.3737    708.7595    741.6662    874.6859
##  [619]    857.2504    805.5725    794.3484    869.4498    945.5836    942.6542
##  [625]    299.8503    431.7905    522.0344    715.5806    820.2246    764.7260
##  [631]    838.1240    736.4154    745.5399    796.6645    575.7047    579.2317
##  [637]   1840.3669   1726.8879   1796.5890   1452.0577   1654.4569   1874.2989
##  [643]   2011.1595   1823.0160   1456.3095   1341.7269   1270.3649   1201.6372
##  [649]   2194.9262   2220.4877   2291.1568   2538.2694   2529.8423   3203.2081
##  [655]   3121.7608   3023.0967   3081.6946   3160.4549   3099.7287   3548.3308
##  [661]   3054.4212   3629.0765   4692.6483   6197.9628   8315.9281  11186.1413
##  [667]  14560.5305  20038.4727  24757.6030  28377.6322  30209.0152  39724.9787
##  [673]   5263.6738   6040.1800   7550.3599   9326.6447  10168.6561  11674.8374
##  [679]  12545.9907  12986.4800  10535.6285  11712.7768  14843.9356  18008.9444
##  [685]   7267.6884   9244.0014  10350.1591  13319.8957  15798.0636  19654.9625
##  [691]  23269.6075  26923.2063  25144.3920  28061.0997  31163.2020  36180.7892
##  [697]    546.5657    590.0620    658.3472    700.7706    724.0325    813.3373
##  [703]    855.7235    976.5127   1164.4068   1458.8174   1746.7695   2452.2104
##  [709]    749.6817    858.9003    849.2898    762.4318   1111.1079   1382.7021
##  [715]   1516.8730   1748.3570   2383.1409   3119.3356   2873.9129   3540.6516
##  [721]   3035.3260   3290.2576   4187.3298   5906.7318   9613.8186  11888.5951
##  [727]   7608.3346   6642.8814   7235.6532   8263.5903   9240.7620  11605.7145
##  [733]   4129.7661   6229.3336   8341.7378   8931.4598   9576.0376  14688.2351
##  [739]  14517.9071  11643.5727   3745.6407   3076.2398   4390.7173   4471.0619
##  [745]   5210.2803   5599.0779   6631.5973   7655.5690   9530.7729  11150.9811
##  [751]  12618.3214  13872.8665  17558.8155  24521.9471  34077.0494  40675.9964
##  [757]   4086.5221   5385.2785   7105.6307   8393.7414  12786.9322  13306.6192
##  [763]  15367.0292  17122.4799  18051.5225  20896.6092  21905.5951  25523.2771
##  [769]   4931.4042   6248.6562   8243.5823  10022.4013  12269.2738  14255.9847
##  [775]  16537.4835  19207.2348  22013.6449  24675.0245  27968.0982  28569.7197
##  [781]   2898.5309   4756.5258   5246.1075   6124.7035   7433.8893   6650.1956
##  [787]   6068.0513   6351.2375   7404.9237   7121.9247   6994.7749   7320.8803
##  [793]   3216.9563   4317.6944   6576.6495   9847.7886  14778.7864  16610.3770
##  [799]  19384.1057  22375.9419  26824.8951  28816.5850  28604.5919  31656.0681
##  [805]   1546.9078   1886.0806   2348.0092   2741.7963   2110.8563   2852.3516
##  [811]   4161.4160   4448.6799   3431.5936   3645.3796   3844.9172   4519.4612
##  [817]    853.5409    944.4383    896.9664   1056.7365   1222.3600   1267.6132
##  [823]   1348.2258   1361.9369   1341.9217   1360.4850   1287.5147   1463.2493
##  [829]   1088.2778   1571.1347   1621.6936   2143.5406   3701.6215   4106.3012
##  [835]   4106.5253   4106.4923   3726.0635   1690.7568   1646.7582   1593.0655
##  [841]   1030.5922   1487.5935   1536.3444   2029.2281   3030.8767   4657.2210
##  [847]   5622.9425   8533.0888  12104.2787  15993.5280  19233.9882  23348.1397
##  [853] 108382.3529 113523.1329  95458.1118  80894.8833 109347.8670  59265.4771
##  [859]  31354.0357  28118.4300  34932.9196  40300.6200  35110.1057  47306.9898
##  [865]   4834.8041   6089.7869   5714.5606   6006.9830   7486.3843   8659.6968
##  [871]   7640.5195   5377.0913   6890.8069   8754.9639   9313.9388  10461.0587
##  [877]    298.8462    335.9971    411.8006    498.6390    496.5816    745.3695
##  [883]    797.2631    773.9932    977.4863   1186.1480   1275.1846   1569.3314
##  [889]    575.5730    620.9700    634.1952    713.6036    803.0055    640.3224
##  [895]    572.1996    506.1139    636.6229    609.1740    531.4824    414.5073
##  [901]   2387.5481   3448.2844   6757.0308  18772.7517  21011.4972  21951.2118
##  [907]  17364.2754  11770.5898   9640.1385   9467.4461   9534.6775  12057.4993
##  [913]   1443.0117   1589.2027   1643.3871   1634.0473   1748.5630   1544.2286
##  [919]   1302.8787   1155.4419   1040.6762    986.2959    894.6371   1044.7701
##  [925]    369.1651    416.3698    427.9011    495.5148    584.6220    663.2237
##  [931]    632.8039    635.5174    563.2000    692.2758    665.4231    759.3499
##  [937]   1831.1329   1810.0670   2036.8849   2277.7424   2849.0948   3827.9216
##  [943]   4920.3560   5249.8027   7277.9128  10132.9096  10206.9779  12451.6558
##  [949]    452.3370    490.3822    496.1743    545.0099    581.3689    686.3953
##  [955]    618.0141    684.1716    739.0144    790.2580    951.4098   1042.5816
##  [961]    743.1159    846.1203   1055.8960   1421.1452   1586.8518   1497.4922
##  [967]   1481.1502   1421.6036   1361.3698   1483.1361   1579.0195   1803.1515
##  [973]   1967.9557   2034.0380   2529.0675   2475.3876   2575.4842   3710.9830
##  [979]   3688.0377   4783.5869   6058.2538   7425.7053   9021.8159  10956.9911
##  [985]   3478.1255   4131.5466   4581.6094   5754.7339   6809.4067   7674.9291
##  [991]   9611.1475   8688.1560   9472.3843   9767.2975  10742.4405  11977.5750
##  [997]    786.5669    912.6626   1056.3540   1226.0411   1421.7420   1647.5117
## [1003]   2000.6031   2338.0083   1785.4020   1902.2521   2140.7393   3095.7723
## [1009]   2647.5856   3682.2599   4649.5938   5907.8509   7778.4140   9595.9299
## [1015]  11222.5876  11732.5102   7003.3390   6465.6133   6557.1943   9253.8961
## [1021]   1688.2036   1642.0023   1566.3535   1711.0448   1930.1950   2370.6200
## [1027]   2702.6204   2755.0470   2948.0473   2982.1019   3258.4956   3820.1752
## [1033]    468.5260    495.5868    556.6864    566.6692    724.9178    502.3197
## [1039]    462.2114    389.8762    410.8968    472.3461    633.6179    823.6856
## [1045]    331.0000    350.0000    388.0000    349.0000    357.0000    371.0000
## [1051]    424.0000    385.0000    347.0000    415.0000    611.0000    944.0000
## [1057]   2423.7804   2621.4481   3173.2156   3793.6948   3746.0809   3876.4860
## [1063]   4191.1005   3693.7313   3804.5380   3899.5243   4072.3248   4811.0604
## [1069]    545.8657    597.9364    652.3969    676.4422    674.7881    694.1124
## [1075]    718.3731    775.6325    897.7404   1010.8921   1057.2063   1091.3598
## [1081]   8941.5719  11276.1934  12790.8496  15363.2514  18794.7457  21209.0592
## [1087]  21399.4605  23651.3236  26790.9496  30246.1306  33724.7578  36797.9333
## [1093]  10556.5757  12247.3953  13175.6780  14463.9189  16046.0373  16233.7177
## [1099]  17632.4104  19007.1913  18363.3249  21050.4138  23189.8014  25185.0091
## [1105]   3112.3639   3457.4159   3634.3644   4643.3935   4688.5933   5486.3711
## [1111]   3470.3382   2955.9844   2170.1517   2253.0230   2474.5488   2749.3210
## [1117]    761.8794    835.5234    997.7661   1054.3849    954.2092    808.8971
## [1123]    909.7221    668.3000    581.1827    580.3052    601.0745    619.6769
## [1129]   1077.2819   1100.5926   1150.9275   1014.5141   1698.3888   1981.9518
## [1135]   1576.9738   1385.0296   1619.8482   1624.9413   1615.2864   2013.9773
## [1141]  10095.4217  11653.9730  13450.4015  16361.8765  18965.0555  23311.3494
## [1147]  26298.6353  31540.9748  33965.6611  41283.1643  44683.9753  49357.1902
## [1153]   1828.2303   2242.7466   2924.6381   4720.9427  10618.0385  11848.3439
## [1159]  12954.7910  18115.2231  18616.7069  19702.0558  19774.8369  22316.1929
## [1165]    684.5971    747.0835    803.3427    942.4083   1049.9390   1175.9212
## [1171]   1443.4298   1704.6866   1971.8295   2049.3505   2092.7124   2605.9476
## [1177]   2480.3803   2961.8009   3536.5403   4421.0091   5364.2497   5351.9121
## [1183]   7009.6016   7034.7792   6618.7431   7113.6923   7356.0319   9809.1856
## [1189]   1952.3087   2046.1547   2148.0271   2299.3763   2523.3380   3248.3733
## [1195]   4258.5036   3998.8757   4196.4111   4247.4003   3783.6742   4172.8385
## [1201]   3758.5234   4245.2567   4957.0380   5788.0933   5937.8273   6281.2909
## [1207]   6434.5018   6360.9434   4446.3809   5838.3477   5909.0201   7408.9056
## [1213]   1272.8810   1547.9448   1649.5522   1814.1274   1989.3741   2373.2043
## [1219]   2603.2738   2189.6350   2279.3240   2536.5349   2650.9211   3190.4810
## [1225]   4029.3297   4734.2530   5338.7521   6557.1528   8006.5070   9508.1415
## [1231]   8451.5310   9082.3512   7738.8812  10159.5837  12002.2391  15389.9247
## [1237]   3068.3199   3774.5717   4727.9549   6361.5180   9022.2474  10172.4857
## [1243]  11753.8429  13039.3088  16207.2666  17641.0316  19970.9079  20509.6478
## [1249]   3081.9598   3907.1562   5108.3446   6929.2777   9123.0417   9770.5249
## [1255]  10330.9891  12281.3419  14641.5871  16999.4333  18855.6062  19328.7090
## [1261]   2718.8853   2769.4518   3173.7233   4021.1757   5047.6586   4319.8041
## [1267]   5267.2194   5303.3775   6101.2558   6071.9414   6316.1652   7670.1226
## [1273]   3144.6132   3943.3702   4734.9976   6470.8665   8011.4144   9356.3972
## [1279]   9605.3141   9696.2733   6598.4099   7346.5476   7885.3601  10808.4756
## [1285]    493.3239    540.2894    597.4731    510.9637    590.5807    670.0806
## [1291]    881.5706    847.9912    737.0686    589.9445    785.6538    863.0885
## [1297]    879.5836    860.7369   1071.5511   1384.8406   1532.9853   1737.5617
## [1303]   1890.2181   1516.5255   1428.7778   1339.0760   1353.0924   1598.4351
## [1309]   6459.5548   8157.5912  11626.4197  16903.0489  24837.4287  34167.7626
## [1315]  33693.1753  21198.2614  24841.6178  20586.6902  19014.5412  21654.8319
## [1321]   1450.3570   1567.6530   1654.9887   1612.4046   1597.7121   1561.7691
## [1327]   1518.4800   1441.7207   1367.8994   1392.3683   1519.6353   1712.4721
## [1333]   3581.4594   4981.0909   6289.6292   7991.7071  10522.0675  12980.6696
## [1339]  15181.0927  15870.8785   9325.0682   7914.3203   7236.0753   9786.5347
## [1345]    879.7877   1004.4844   1116.6399   1206.0435   1353.7598   1348.2852
## [1351]   1465.0108   1294.4478   1068.6963    574.6482    699.4897    862.5408
## [1357]   2315.1382   2843.1044   3674.7356   4977.4185   8597.7562  11210.0895
## [1363]  15169.1611  18861.5308  24769.8912  33519.4766  36023.1054  47143.1796
## [1369]   5074.6591   6093.2630   7481.1076   8412.9024   9674.1676  10922.6640
## [1375]  11348.5459  12037.2676   9498.4677  12126.2306  13638.7784  18678.3144
## [1381]   4215.0417   5862.2766   7402.3034   9405.4894  12383.4862  15277.0302
## [1387]  17866.7218  18678.5349  14214.7168  17161.1073  20660.0194  25768.2576
## [1393]   1135.7498   1258.1474   1369.4883   1284.7332   1254.5761   1450.9925
## [1399]   1176.8070   1093.2450    926.9603    930.5964    882.0818    926.1411
## [1405]   4725.2955   5487.1042   5768.7297   7114.4780   7765.9626   8028.6514
## [1411]   8568.2662   7825.8234   7225.0693   7479.1882   7710.9464   9269.6578
## [1417]   3834.0347   4564.8024   5693.8439   7993.5123  10638.7513  13236.9212
## [1423]  13926.1700  15764.9831  18603.0645  20445.2990  24835.4717  28821.0637
## [1429]   1083.5320   1072.5466   1074.4720   1135.5143   1213.3955   1348.7757
## [1435]   1648.0798   1876.7668   2153.7392   2664.4773   3015.3788   3970.0954
## [1441]   1615.9911   1770.3371   1959.5938   1687.9976   1659.6528   2202.9884
## [1447]   1895.5441   1507.8192   1492.1970   1632.2108   1993.3983   2602.3950
## [1453]   1148.3766   1244.7084   1856.1821   2613.1017   3364.8366   3781.4106
## [1459]   3895.3840   3984.8398   3553.0224   3876.7685   4128.1169   4513.4806
## [1465]   8527.8447   9911.8782  12329.4419  15258.2970  17832.0246  18855.7252
## [1471]  20667.3812  23586.9293  23880.0168  25266.5950  29341.6309  33859.7484
## [1477]  14734.2327  17909.4897  20431.0927  22966.1443  27195.1130  26982.2905
## [1483]  28397.7151  30281.7046  31871.5303  32135.3230  34480.9577  37506.4191
## [1489]   1643.4854   2117.2349   2193.0371   1881.9236   2571.4230   3195.4846
## [1495]   3761.8377   3116.7743   3340.5428   4014.2390   4090.9253   4184.5481
## [1501]   1206.9479   1507.8613   1822.8790   2643.8587   4062.5239   5596.5198
## [1507]   7426.3548  11054.5618  15215.6579  20206.8210  23235.4233  28718.2768
## [1513]    716.6501    698.5356    722.0038    848.2187    915.9851    962.4923
## [1519]    874.2426    831.8221    825.6825    789.1862    899.0742   1107.4822
## [1525]    757.7974    793.5774   1002.1992   1295.4607   1524.3589   1961.2246
## [1531]   2393.2198   2982.6538   4616.8965   5852.6255   5913.1875   7458.3963
## [1537]    859.8087    925.9083   1067.5348   1477.5968   1649.6602   1532.7770
## [1543]   1344.5780   1202.2014   1034.2989    982.2869    886.2206    882.9699
## [1549]   3023.2719   4100.3934   4997.5240   5621.3685   6619.5514   7899.5542
## [1555]   9119.5286   7388.5978   7370.9909   8792.5731  11460.6002  18008.5092
## [1561]   1468.4756   1395.2325   1660.3032   1932.3602   2753.2860   3120.8768
## [1567]   3560.2332   3810.4193   4332.7202   4876.7986   5722.8957   7092.9230
## [1573]   1969.1010   2218.7543   2322.8699   2826.3564   3450.6964   4269.1223
## [1579]   4241.3563   5089.0437   5678.3483   6601.4299   6508.0857   8458.2764
## [1585]    734.7535    774.3711    767.2717    908.9185    950.7359    843.7331
## [1591]    682.2662    617.7244    644.1708    816.5591    927.7210   1056.3801
## [1597]   9979.5085  11283.1779  12477.1771  14142.8509  15895.1164  17428.7485
## [1603]  18232.4245  21664.7877  22705.0925  26074.5314  29478.9992  33203.2613
## [1609]  13990.4821  14847.1271  16173.1459  19530.3656  21806.0359  24072.6321
## [1615]  25009.5591  29884.3504  32003.9322  35767.4330  39097.0995  42951.6531
## [1621]   5716.7667   6150.7730   5603.3577   5444.6196   5703.4089   6504.3397
## [1627]   6920.2231   7452.3990   8137.0048   9230.2407   7727.0020  10611.4630
## [1633]   7689.7998   9802.4665   8422.9742   9541.4742  10505.2597  13143.9510
## [1639]  11152.4101   9883.5846  10733.9263  10165.4952   8605.0478  11415.8057
## [1645]    605.0665    676.2854    772.0492    637.1233    699.5016    713.5371
## [1651]    707.2358    820.7994    989.0231   1385.8968   1764.4567   2441.5764
## [1657]   1515.5923   1827.0677   2198.9563   2649.7150   3133.4093   3682.8315
## [1663]   4336.0321   5107.1974   6017.6548   7110.6676   4515.4876   3025.3498
## [1669]    781.7176    804.8305    825.6232    862.4421   1265.0470   1829.7652
## [1675]   1977.5570   1971.7415   1879.4967   2117.4845   2234.8208   2280.7699
## [1681]   1147.3888   1311.9568   1452.7258   1777.0773   1773.4983   1588.6883
## [1687]   1408.6786   1213.3151   1210.8846   1071.3538   1071.6139   1271.2116
## [1693]    406.8841    518.7643    527.2722    569.7951    799.3622    685.5877
## [1699]    788.8550    706.1573    693.4208    792.4500    672.0386    469.7093

Very good! There are a lot of numbers here.

I have some Ideas for visuals, but lets make our variables more accessible first…

attach(gapminder)

Lets find the median of the Population variable: “pop”

median(pop)
## [1] 7023596

Now lets see some visuals with histograms with the “hist” command.

hist(lifeExp)

hist(gdpPercap)

hist(pop)

Lets use the natural logarithm to clean up the histogram of variable “pop.”

hist(log(pop))

Nice!

Now to compare the variables “Life Expectancy” vs. “Continent” within a box plot

boxplot(lifeExp ~ continent)

That was good. What would a scatter plot look like though?

plot(lifeExp ~ log(gdpPercap))

It’s time to get a more detailed breakdown of our data, but first we need to install the “dplyr” package within R, and confirm its within our library.

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
install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(dplyr)

Now lets select our data, group it, and “pipe” it using our newly installed data manipulation package “dplyr.”

gapminder %>%
  select(country, lifeExp) %>%
  filter(country == "Nigeria" |country == "Canada" | country == "Mexico" | country == "Ghana" | country == "Ireland" | country == "Italy") %>%
  group_by(country) %>%
  summarise(Average_life = mean(lifeExp))
## # A tibble: 6 × 2
##   country Average_life
##   <fct>          <dbl>
## 1 Canada          74.9
## 2 Ghana           52.3
## 3 Ireland         73.0
## 4 Italy           74.0
## 5 Mexico          65.4
## 6 Nigeria         43.6

That’s our “Tibble” of data comparing various countries.

Lets define a variable and use “pipe” again to compare two randomly picked countries from our list.

df1 <- gapminder %>%
  select(country, lifeExp) %>%
  filter(country == "Ghana" | country == "Italy")

Now lets run a “T-test” to discover a numerical analysis

t.test(data = df1, lifeExp ~ country)
## 
##  Welch Two Sample t-test
## 
## data:  lifeExp by country
## t = -9.8594, df = 21.316, p-value = 2.139e-09
## alternative hypothesis: true difference in means between group Ghana and group Italy is not equal to 0
## 95 percent confidence interval:
##  -26.24052 -17.10582
## sample estimates:
## mean in group Ghana mean in group Italy 
##            52.34067            74.01383

We were able to discover the significant difference in variables betweem the two countries.

Now lets load our visualiztion package, “ggplot2” to see what this data looks like.

install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(ggplot2)

Lets see what they look like in their own scatter plots using the “pipe” function and filtering by country, and summarizing with a comparison of average life cycle and mean of life expectancy. We will set the ‘y’ axis as the life expectancy, and ‘x’ axis as a natural logarithm of GDP per capita. Size of our populations will reflect the size of our countries within each continent, and color will be year.

Here’s the code we need to generate our visual

gapminder %>%
    filter(gdpPercap < 50000) %>%
    ggplot(aes(x=log(gdpPercap), y=lifeExp, col=year, size = pop))+
geom_point(alpha=0.3)+
geom_smooth(method = lm)+
(facet_wrap(~continent))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
## Warning: The following aesthetics were dropped during statistical transformation: colour
## and size.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
## Warning: The following aesthetics were dropped during statistical transformation: colour
## and size.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
## The following aesthetics were dropped during statistical transformation: colour
## and size.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
## The following aesthetics were dropped during statistical transformation: colour
## and size.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
## The following aesthetics were dropped during statistical transformation: colour
## and size.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?

It looks like R studio didn’t like some of our code and did away with a few items including the size aspect of each country, But that’s fine! Our visuals look great.