Project Summary:

The project involves choosing any 3 “wide”“,”messy“” data sets from Week 6 discussion topic, transform and tidying up the data using tidyr and dplyr packages. After converting the data sets in a tidy format, analysis to be performed on each of the data sets as suggested in the discussion forum.

R Libraries:

Load necessary libraries -

library(kableExtra)
library(stringr)
library(dplyr)
library(tidyr)
library(ggplot2)

Data Set 1: United Nations Migrants Data Set By Origin and Destination By Gender

The dataset presents estimates of international migrant by age, sex and origin. Estimates are presented for 1990, 1995, 2000, 2005, 2010, 2015 and 2017 and are available for all countries and areas of the world. The estimates are based on official statistics on the foreign-born or the foreign population.

Link to Data Source: UN WebSite

Data Screen Shot:

Below are the steps to be followed for extracting, cleansing and processing data to generate the final output -

  1. Convert the data sets into CSV fromat -

‘Table 2’ and ‘Table 3’ tabs (for Male and Female data) in the Excel File are saved separately into two csv files excluding first 14 records in the file (to exclude the section above header).

  1. Import data into R:
## Male Data
migrantMaleDF <- read.delim("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-607/Tidy%20Data%20Project/Source%20Data/UN_MigrantStockByOriginAndDestination_2017_M.csv",header = TRUE, stringsAsFactors = FALSE, sep = ",")
migrantMaleDF$Gender <- "Male"
head(migrantMaleDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Year Sort.order Major.area..region..country.or.area.of.destination Notes Code Type.of.data..a. Total Other.North Other.South Afghanistan Albania Algeria American.Samoa Andorra Angola Anguilla Antigua.and.Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia..Plurinational.State.of. Bosnia.and.Herzegovina Botswana Brazil British.Virgin.Islands Brunei.Darussalam Bulgaria Burkina.Faso Burundi Cabo.Verde Cambodia Cameroon Canada Caribbean.Netherlands Cayman.Islands Central.African.Republic Chad Channel.Islands Chile China China..Hong.Kong.SAR China..Macao.SAR Colombia Comoros Congo Cook.Islands Costa.Rica Côte.d.Ivoire Croatia Cuba Curaçao Cyprus Czechia Dem..People.s.Republic.of.Korea Democratic.Republic.of.the.Congo Denmark Djibouti Dominica Dominican.Republic Ecuador Egypt El.Salvador Equatorial.Guinea Eritrea Estonia Ethiopia Faeroe.Islands Falkland.Islands..Malvinas. Fiji Finland France French.Guiana French.Polynesia Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guinea Guinea.Bissau Guyana Haiti Holy.See Honduras Hungary Iceland India Indonesia Iran..Islamic.Republic.of. Iraq Ireland Isle.of.Man Israel Italy Jamaica Japan Jordan Kazakhstan Kenya Kiribati Kuwait Kyrgyzstan Lao.People.s.Democratic.Republic Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Madagascar Malawi Malaysia Maldives Mali Malta Marshall.Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia..Fed..States.of. Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands New.Caledonia New.Zealand Nicaragua Niger Nigeria Niue Northern.Mariana.Islands Norway Oman Pakistan Palau Panama Papua.New.Guinea Paraguay Peru Philippines Poland Portugal Puerto.Rico Qatar Republic.of.Korea Republic.of.Moldova Réunion Romania Russian.Federation Rwanda Saint.Helena Saint.Kitts.and.Nevis Saint.Lucia Saint.Pierre.and.Miquelon Saint.Vincent.and.the.Grenadines Samoa San.Marino Sao.Tome.and.Principe Saudi.Arabia Senegal Serbia Seychelles Sierra.Leone Singapore Sint.Maarten..Dutch.part. Slovakia Slovenia Solomon.Islands Somalia South.Africa South.Sudan Spain Sri.Lanka State.of.Palestine Sudan Suriname Swaziland Sweden Switzerland Syrian.Arab.Republic Tajikistan TFYR.Macedonia Thailand Timor.Leste Togo Tokelau Tonga Trinidad.and.Tobago Tunisia Turkey Turkmenistan Turks.and.Caicos.Islands Tuvalu Uganda Ukraine United.Arab.Emirates United.Kingdom United.Republic.of.Tanzania United.States.of.America United.States.Virgin.Islands Uruguay Uzbekistan Vanuatu Venezuela..Bolivarian.Republic.of. Viet.Nam Wallis.and.Futuna.Islands Western.Sahara Yemen Zambia Zimbabwe Gender
1990 1990001 WORLD 900 77,456,347 1,060,798 3,322,039 3,661,547 109,056 512,243 1,049 1,769 397,396 1,069 9,812 203,688 436,884 4,742 140,585 234,591 767,243 10,622 6,067 3,162,730 40,152 816,810 157,228 15,090 126,799 34,703 13,863 115,457 428,195 19,227 226,262 1,340 15,605 302,345 571,852 174,024 42,805 174,414 59,783 366,550 2,165 192 24,146 168,156 8,755 246,732 2,198,341 272,012 48,482 458,549 22,058 48,201 8,377 29,265 188,007 214,453 399,117 21,274 90,730 130,392 18,753 199,663 91,877 2,876 19,272 198,326 105,553 822,199 608,502 16,940 89,624 54,329 854,717 2,992 141 43,625 101,880 566,452 1,253 1,595 7,661 20,713 446,549 1,503,513 188,537 5,671 542,735 3,774 19,604 2,590 694 173,120 201,470 27,391 110,776 294,362 14 66,894 191,820 8,633 3,857,101 951,535 361,354 854,938 413,377 5,098 137,827 1,779,050 268,141 301,582 187,244 1,427,024 118,536 1,937 45,161 252,656 236,885 99,955 290,900 146,090 260,528 39,985 1,448 152,616 13,734 25,385 71,829 276,624 1,698 360,704 56,493 708 5,609 74,892 50,677 986 2,357,870 3,935 2,213 11,630 39,492 3,366 902,650 1,200,919 376,096 9,351 626 389,287 363,337 1,928 196,149 219,783 84,774 256,747 2,832 1,204 59,890 6,450 1,970,220 1,369 66,554 1,509 131,618 149,880 834,460 717,210 969,080 574,866 6,028 815,465 290,663 1,571 377,026 5,521,935 278,431 386 9,534 10,053 240 17,900 36,602 569 6,725 57,708 230,217 375,377 14,033 31,381 74,426 7,331 66,110 40,067 1,134 448,139 160,035 266,794 690,938 458,991 888,313 336,705 87,491 25,591 87,956 143,912 354,953 263,716 215,990 122,347 5,921 95,160 836 16,197 87,603 273,859 1,308,220 127,448 1,006 1,203 157,808 2,636,852 44,694 1,876,977 107,733 868,212 1,175 116,376 686,783 2,646 83,042 635,164 3,664 92,655 290,279 41,050 90,471 Male
1990 1990002 More developed regions b 901 40,270,398 522,085 1,826,518 69,683 107,782 485,698 505 1,735 80,074 280 6,590 100,790 321,121 2,020 109,138 218,189 515,511 9,735 952 93,050 37,391 726,178 143,609 13,285 8,080 34,623 291 20,940 424,148 1,508 113,992 84 3,341 62,989 3,516 1,911 36,603 114,437 24,378 336,361 1,437 141 4,573 2,069 8,720 87,562 722,857 254,737 6,926 156,772 9,291 30,326 8,358 19,472 24,168 212,521 368,021 19,613 85,819 126,417 7,202 32,812 88,180 1,818 11,345 165,967 80,987 158,971 257,128 3,319 12,913 52,698 57,044 2,992 130 41,695 100,427 388,602 29 137 4,187 8,511 392,338 1,107,340 73,007 5,633 471,068 3,587 10,793 81 22 121,197 8,442 9,503 97,918 144,509 6 48,330 179,268 8,589 633,811 150,279 301,290 85,814 409,455 5,098 87,313 1,487,482 262,398 204,564 48,780 1,368,060 78,678 444 8,428 234,526 126,221 93,411 206,659 178 9,953 14,070 1,336 138,557 13,606 17,817 5,994 92,037 163 33,313 56,391 548 158 9,079 45,387 .. 2,337,159 1,352 2,092 11,543 39,375 2,413 814,038 37,752 21,826 623 217 4,496 332,771 536 187,537 85,577 1,992 89,169 2,812 136 55,383 416 259,303 6 43,987 870 5,913 101,284 507,839 631,417 752,337 565,279 477 685,575 263,522 64 307,870 3,284,119 3,375 283 4,522 4,593 211 9,411 28,658 533 2,745 12,148 93,787 373,783 13,790 10,487 41,882 6,998 65,806 39,098 530 34,408 106,165 .. 432,631 148,713 18,881 9,433 77,305 268 82,964 123,661 75,462 229,236 189,945 70,479 5,436 10,867 755 14,745 80,657 249,632 1,258,096 122,637 107 550 36,292 2,243,566 3,210 1,714,045 31,189 434,712 39 26,490 521,086 461 48,465 556,402 743 265 7,250 12,896 19,593 Male
1990 1990003 Less developed regions c 902 37,185,949 538,713 1,495,521 3,591,864 1,274 26,545 544 34 317,322 789 3,222 102,898 115,763 2,722 31,447 16,402 251,732 887 5,115 3,069,680 2,761 90,632 13,619 1,805 118,719 80 13,572 94,517 4,047 17,719 112,270 1,256 12,264 239,356 568,336 172,113 6,202 59,977 35,405 30,189 728 51 19,573 166,087 35 159,170 1,475,484 17,275 41,556 301,777 12,767 17,875 19 9,793 163,839 1,932 31,096 1,661 4,911 3,975 11,551 166,851 3,697 1,058 7,927 32,359 24,566 663,228 351,374 13,621 76,711 1,631 797,673 .. 11 1,930 1,453 177,850 1,224 1,458 3,474 12,202 54,211 396,173 115,530 38 71,667 187 8,811 2,509 672 51,923 193,028 17,888 12,858 149,853 8 18,564 12,552 44 3,223,290 801,256 60,064 769,124 3,922 .. 50,514 291,568 5,743 97,018 138,464 58,964 39,858 1,493 36,733 18,130 110,664 6,544 84,241 145,912 250,575 25,915 112 14,059 128 7,568 65,835 184,587 1,535 327,391 102 160 5,451 65,813 5,290 986 20,711 2,583 121 87 117 953 88,612 1,163,167 354,270 8,728 409 384,791 30,566 1,392 8,612 134,206 82,782 167,578 20 1,068 4,507 6,034 1,710,917 1,363 22,567 639 125,705 48,596 326,621 85,793 216,743 9,587 5,551 129,890 27,141 1,507 69,156 2,237,816 275,056 103 5,012 5,460 29 8,489 7,944 36 3,980 45,560 136,430 1,594 243 20,894 32,544 333 304 969 604 413,731 53,870 266,794 258,307 310,278 869,432 327,272 10,186 25,323 4,992 20,251 279,491 34,480 26,045 51,868 485 84,293 81 1,452 6,946 24,227 50,124 4,811 899 653 121,516 393,286 41,484 162,932 76,544 433,500 1,136 89,886 165,697 2,185 34,577 78,762 2,921 92,390 283,029 28,154 70,878 Male
1990 1990004 Least developed countries d 941 5,556,516 141,569 272,883 .. .. 2,474 .. .. 288,361 .. .. 296 .. .. 809 155 .. .. 49 1,286 .. .. 503 .. 21,560 .. 8,065 .. .. 278 843 .. .. .. 21,746 170,263 6,021 7,676 17,913 978 .. .. 13,807 104,440 .. 214 129,816 31 .. 421 4,777 12,930 .. 106 159,061 .. 743 .. 3 .. 60 127,783 109 475 .. 1,345 .. 16,060 .. 152 69,934 .. 714,497 .. .. 376 .. 20,194 .. .. 2,815 6,647 .. 2,568 27,607 .. 21 .. .. .. .. .. 118,202 16,933 .. .. .. .. .. .. 158,366 40,346 .. 2,776 .. .. .. 1,709 .. 5,326 .. .. 33,312 483 9 .. 31,777 .. 4,498 1,648 239,503 1,934 .. .. .. 5,007 15,533 50,228 .. 66,996 .. .. .. 55,794 70 .. 131 .. .. .. .. .. 1,778 621,383 106,389 1,683 399 5,453 300 128 271 .. 21,865 59,176 .. .. 2,290 .. 10,703 .. .. 592 .. 208 476 .. 7,993 703 .. 171 .. 507 .. 776 271,618 .. .. .. .. .. 18 .. 1,659 1,038 104,773 .. 129 19,179 5,773 .. .. 8 39 400,799 21,362 257,061 1,069 68 1,482 125,226 .. 58 599 400 1,313 22,879 .. 16,699 .. 12,586 .. 14 .. 92 1 .. .. 203 75,525 39 24 8,575 39,091 20,547 .. 112 1,144 3 1,325 36,996 .. .. 175 10,213 22,057 Male
1990 1990005 Less developed regions, excluding least developed countries 934 31,629,433 397,144 1,222,638 3,591,864 1,274 24,071 544 34 28,961 789 3,222 102,602 115,763 2,722 30,638 16,247 251,732 887 5,066 3,068,394 2,761 90,632 13,116 1,805 97,159 80 5,507 94,517 4,047 17,441 111,427 1,256 12,264 239,356 546,590 1,850 181 52,301 17,492 29,211 728 51 5,766 61,647 35 158,956 1,345,668 17,244 41,556 301,356 7,990 4,945 19 9,687 4,778 1,932 30,353 1,661 4,908 3,975 11,491 39,068 3,588 583 7,927 31,014 24,566 647,168 351,374 13,469 6,777 1,631 83,176 .. 11 1,554 1,453 157,656 1,224 1,458 659 5,555 54,211 393,605 87,923 38 71,646 187 8,811 2,509 672 51,923 74,826 955 12,858 149,853 8 18,564 12,552 44 3,064,924 760,910 60,064 766,348 3,922 .. 50,514 289,859 5,743 91,692 138,464 58,964 6,546 1,010 36,724 18,130 78,887 6,544 79,743 144,264 11,072 23,981 112 14,059 128 2,561 50,302 134,359 1,535 260,395 102 160 5,451 10,019 5,220 986 20,580 2,583 121 87 117 953 86,834 541,784 247,881 7,045 10 379,338 30,266 1,264 8,341 134,206 60,917 108,402 20 1,068 2,217 6,034 1,700,214 1,363 22,567 47 125,705 48,388 326,145 85,793 208,750 8,884 5,551 129,719 27,141 1,000 69,156 2,237,040 3,438 103 5,012 5,460 29 8,489 7,926 36 2,321 44,522 31,657 1,594 114 1,715 26,771 333 304 961 565 12,932 32,508 9,733 257,238 310,210 867,950 202,046 10,186 25,265 4,393 19,851 278,178 11,601 26,045 35,169 485 71,707 81 1,438 6,946 24,135 50,123 4,811 899 450 45,991 393,247 41,460 154,357 37,453 412,953 1,136 89,774 164,553 2,182 33,252 41,766 2,921 92,390 282,854 17,941 48,821 Male
1990 1990006 High-income countries e 1503 38,788,286 568,557 2,015,506 172,391 88,240 494,912 34 1,742 79,820 706 8,910 135,200 39,004 2,243 115,779 218,278 17,270 10,235 1,110 806,820 39,175 165,636 145,164 13,368 7,924 34,667 294 24,256 253,126 1,411 125,743 1,276 3,341 53,956 3,256 1,834 36,577 114,559 24,033 345,131 1,633 149 4,516 6,525 8,723 89,439 1,771,430 268,157 41,624 160,132 9,285 30,077 8,358 19,959 24,120 184,504 376,584 19,853 85,520 119,084 2,605 32,898 87,369 1,817 15,809 183,987 82,108 600,096 257,487 3,307 18,386 15,829 122,153 2,992 132 41,709 99,094 421,021 31 1,553 4,190 8,510 44,697 1,050,836 72,893 5,634 454,033 3,589 19,050 104 621 121,517 8,227 9,337 102,791 152,881 14 49,008 173,509 8,578 2,056,251 723,130 320,736 143,591 409,774 5,098 84,195 1,491,802 265,887 214,048 139,233 28,741 78,514 443 22,722 3,337 126,425 37,029 252,694 184 9,958 23,174 1,336 85,220 13,563 17,754 5,989 207,065 97 33,221 56,117 636 162 9,085 45,382 .. 2,339,382 3,875 1,999 1,156 28,919 3,229 891,936 37,705 81,264 572 217 149,078 337,705 1,367 189,322 85,950 1,985 90,811 2,812 1,000 54,858 415 912,063 1,150 45,045 872 7,183 105,451 760,588 659,668 754,496 567,895 458 689,508 30,447 64 363,209 762,161 3,288 283 8,212 8,042 213 17,374 28,658 522 2,751 21,410 93,745 357,778 13,791 10,489 45,959 7,068 62,985 26,550 530 37,784 110,843 3,222 457,753 307,243 36,518 170,018 77,690 269 83,360 125,046 263,535 4,795 178,181 83,203 5,436 10,868 755 14,746 83,224 270,639 1,272,725 25,021 1,002 533 36,256 460,186 31,152 1,756,615 31,083 615,513 746 29,017 32,571 2,290 51,932 535,732 3,658 211 275,071 12,733 19,497 Male
## Female Data
migrantFemaleDF <- read.delim("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-607/Tidy%20Data%20Project/Source%20Data/UN_MigrantStockByOriginAndDestination_2017_F.csv",header = TRUE, stringsAsFactors = FALSE, sep = ",")
head(migrantFemaleDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Year Sort.order Major.area..region..country.or.area.of.destination Notes Code Type.of.data..a. Total Other.North Other.South Afghanistan Albania Algeria American.Samoa Andorra Angola Anguilla Antigua.and.Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia..Plurinational.State.of. Bosnia.and.Herzegovina Botswana Brazil British.Virgin.Islands Brunei.Darussalam Bulgaria Burkina.Faso Burundi Cabo.Verde Cambodia Cameroon Canada Caribbean.Netherlands Cayman.Islands Central.African.Republic Chad Channel.Islands Chile China China..Hong.Kong.SAR China..Macao.SAR Colombia Comoros Congo Cook.Islands Costa.Rica Côte.d.Ivoire Croatia Cuba Curaçao Cyprus Czechia Dem..People.s.Republic.of.Korea Democratic.Republic.of.the.Congo Denmark Djibouti Dominica Dominican.Republic Ecuador Egypt El.Salvador Equatorial.Guinea Eritrea Estonia Ethiopia Faeroe.Islands Falkland.Islands..Malvinas. Fiji Finland France French.Guiana French.Polynesia Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guinea Guinea.Bissau Guyana Haiti Holy.See Honduras Hungary Iceland India Indonesia Iran..Islamic.Republic.of. Iraq Ireland Isle.of.Man Israel Italy Jamaica Japan Jordan Kazakhstan Kenya Kiribati Kuwait Kyrgyzstan Lao.People.s.Democratic.Republic Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Madagascar Malawi Malaysia Maldives Mali Malta Marshall.Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia..Fed..States.of. Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands New.Caledonia New.Zealand Nicaragua Niger Nigeria Niue Northern.Mariana.Islands Norway Oman Pakistan Palau Panama Papua.New.Guinea Paraguay Peru Philippines Poland Portugal Puerto.Rico Qatar Republic.of.Korea Republic.of.Moldova Réunion Romania Russian.Federation Rwanda Saint.Helena Saint.Kitts.and.Nevis Saint.Lucia Saint.Pierre.and.Miquelon Saint.Vincent.and.the.Grenadines Samoa San.Marino Sao.Tome.and.Principe Saudi.Arabia Senegal Serbia Seychelles Sierra.Leone Singapore Sint.Maarten..Dutch.part. Slovakia Slovenia Solomon.Islands Somalia South.Africa South.Sudan Spain Sri.Lanka State.of.Palestine Sudan Suriname Swaziland Sweden Switzerland Syrian.Arab.Republic Tajikistan TFYR.Macedonia Thailand Timor.Leste Togo Tokelau Tonga Trinidad.and.Tobago Tunisia Turkey Turkmenistan Turks.and.Caicos.Islands Tuvalu Uganda Ukraine United.Arab.Emirates United.Kingdom United.Republic.of.Tanzania United.States.of.America United.States.Virgin.Islands Uruguay Uzbekistan Vanuatu Venezuela..Bolivarian.Republic.of. Viet.Nam Wallis.and.Futuna.Islands Western.Sahara Yemen Zambia Zimbabwe
1990 1990001 WORLD 900 75,086,026 1,083,738 3,020,492 3,063,134 70,434 393,787 992 2,023 412,546 978 11,935 226,634 462,799 5,855 162,821 271,227 866,877 14,550 6,700 2,288,816 44,765 952,219 208,186 21,024 106,843 37,000 14,503 109,230 435,204 6,810 273,887 1,754 10,718 314,810 447,016 163,175 48,876 180,194 55,528 630,594 2,160 181 22,094 168,760 9,972 243,223 2,031,519 279,068 47,166 550,599 18,018 43,101 9,111 40,459 182,859 211,748 436,429 20,604 83,634 147,122 19,821 202,299 110,317 2,405 23,094 266,696 108,178 498,929 633,375 18,032 80,993 59,599 832,800 4,532 119 46,531 148,810 630,645 1,595 1,554 7,547 15,436 473,892 1,774,164 184,766 6,323 498,720 5,736 23,646 3,238 682 170,503 151,120 27,929 122,884 232,945 18 89,659 195,114 9,002 2,861,761 684,791 268,480 651,741 504,262 5,637 141,129 1,637,371 320,679 307,450 126,493 1,545,409 123,583 2,116 36,321 269,959 245,209 115,210 215,700 45,903 256,191 36,086 1,982 188,467 14,094 33,248 49,536 285,993 494 287,040 54,242 720 5,432 59,237 57,708 849 2,036,814 3,779 2,194 12,525 39,186 3,822 685,568 1,017,090 309,192 6,706 786 358,759 365,473 2,223 191,940 222,254 47,952 191,713 3,028 1,321 78,647 6,084 1,371,354 1,589 68,149 1,506 166,307 163,715 1,194,730 816,096 911,647 625,969 6,176 809,332 335,147 1,516 436,061 7,142,602 272,288 498 11,180 11,953 245 19,143 38,259 846 7,216 49,329 139,046 333,427 15,343 29,571 81,775 7,037 67,351 51,585 1,078 398,828 167,626 248,149 758,378 426,845 924,755 250,358 92,166 9,593 119,111 179,321 265,915 272,536 213,565 186,741 5,340 98,209 848 16,469 109,919 180,074 1,222,399 132,543 1,305 1,147 153,682 2,912,625 34,846 1,918,685 96,539 868,076 1,187 120,882 743,173 2,414 102,846 600,184 2,820 75,584 165,163 42,160 86,226
1990 1990002 More developed regions b 901 42,121,221 572,738 1,585,626 49,655 69,410 365,653 522 2,002 86,672 260 7,965 121,628 333,028 2,620 135,773 253,478 541,071 13,630 778 67,755 42,157 845,537 194,460 18,894 6,112 36,927 164 21,801 431,834 1,319 168,287 74 3,282 59,682 2,676 1,840 43,293 122,015 25,271 601,086 1,406 128 4,419 1,431 9,905 100,402 735,320 262,012 7,456 207,035 9,648 26,063 9,083 28,549 24,757 209,974 406,322 19,058 78,152 142,300 7,222 27,949 106,586 1,621 12,398 220,387 83,970 109,842 250,316 3,971 12,666 57,491 57,412 4,530 107 44,292 146,578 473,383 32 187 4,386 4,043 410,359 1,349,139 53,149 6,287 419,919 5,410 13,033 81 21 119,376 6,102 6,514 108,875 148,700 5 65,942 180,316 8,956 596,219 157,827 215,635 59,338 499,839 5,637 79,370 1,367,026 312,560 225,793 21,487 1,466,602 75,653 545 7,868 248,554 124,629 107,274 161,080 185 8,234 11,116 1,916 171,774 13,858 24,892 5,574 96,036 140 17,915 54,098 569 158 3,856 53,907 .. 2,012,608 1,412 2,036 12,446 39,062 2,761 593,667 41,037 22,850 659 248 2,667 333,139 732 183,857 93,320 1,306 58,532 3,009 138 74,829 297 185,921 6 46,084 879 8,554 125,529 837,291 714,605 725,545 615,648 427 696,822 303,770 61 353,216 4,283,957 3,188 256 5,364 5,515 222 9,003 30,900 839 3,103 12,625 35,913 331,450 15,155 8,329 48,405 6,800 67,096 50,519 585 31,880 116,030 1 494,198 111,292 16,724 5,585 82,862 281 114,379 161,431 49,878 242,004 188,081 133,317 5,078 7,870 768 15,229 102,247 155,209 1,180,941 126,580 114 621 34,725 2,428,585 2,385 1,749,490 29,722 450,822 31 30,072 557,513 556 66,170 526,613 141 68 4,157 13,026 21,239
1990 1990003 Less developed regions c 902 32,964,805 511,000 1,434,866 3,013,479 1,024 28,134 470 21 325,874 718 3,970 105,006 129,771 3,235 27,048 17,749 325,806 920 5,922 2,221,061 2,608 106,682 13,726 2,130 100,731 73 14,339 87,429 3,370 5,491 105,600 1,680 7,436 255,128 444,340 161,335 5,583 58,179 30,257 29,508 754 53 17,675 167,329 67 142,821 1,296,199 17,056 39,710 343,564 8,370 17,038 28 11,910 158,102 1,774 30,107 1,546 5,482 4,822 12,599 174,350 3,731 784 10,696 46,309 24,208 389,087 383,059 14,061 68,327 2,108 775,388 2 12 2,239 2,232 157,262 1,563 1,367 3,161 11,393 63,533 425,025 131,617 36 78,801 326 10,613 3,157 661 51,127 145,018 21,415 14,009 84,245 13 23,717 14,798 46 2,265,542 526,964 52,845 592,403 4,423 .. 61,759 270,345 8,119 81,657 105,006 78,807 47,930 1,571 28,453 21,405 120,580 7,936 54,620 45,718 247,957 24,970 66 16,693 236 8,356 43,962 189,957 354 269,125 144 151 5,274 55,381 3,801 849 24,206 2,367 158 79 124 1,061 91,901 976,053 286,342 6,047 538 356,092 32,334 1,491 8,083 128,934 46,646 133,181 19 1,183 3,818 5,787 1,185,433 1,583 22,065 627 157,753 38,186 357,439 101,491 186,102 10,321 5,749 112,510 31,377 1,455 82,845 2,858,645 269,100 242 5,816 6,438 23 10,140 7,359 7 4,113 36,704 103,133 1,977 188 21,242 33,370 237 255 1,066 493 366,948 51,596 248,148 264,180 315,553 908,031 244,773 9,304 9,312 4,732 17,890 216,037 30,532 25,484 53,424 262 90,339 80 1,240 7,672 24,865 41,458 5,963 1,191 526 118,957 484,040 32,461 169,195 66,817 417,254 1,156 90,810 185,660 1,858 36,676 73,571 2,679 75,516 161,006 29,134 64,987
1990 1990004 Least developed countries d 941 5,516,710 109,006 260,135 .. .. 3,113 .. .. 305,380 .. .. 230 .. .. 656 35 .. .. 40 761 .. .. 471 .. 20,173 .. 8,740 .. .. 374 788 .. .. .. 19,149 160,291 5,419 6,646 15,467 901 .. .. 12,633 103,945 .. 119 116,112 23 .. 407 3,772 12,382 .. 168 154,251 .. 606 .. 2 .. 19 129,634 86 429 .. 1,061 .. 14,478 .. 203 64,537 .. 718,459 .. .. 345 .. 18,492 .. .. 2,458 6,388 .. 2,216 34,991 .. 20 .. .. .. .. .. 82,747 20,697 .. .. .. .. .. .. 304,393 34,900 .. 2,244 1 .. .. 706 .. 4,406 .. .. 41,691 571 20 .. 27,066 .. 2,939 1,962 238,230 1,774 .. .. .. 5,803 11,026 42,652 .. 65,722 .. .. .. 51,968 43 .. 175 .. .. .. .. .. 1,933 643,778 119,906 1,397 522 4,572 255 164 216 .. 17,150 57,265 .. .. 1,950 .. 6,970 .. .. 568 .. 143 342 .. 5,033 843 .. 185 .. 450 .. 699 265,642 .. .. .. .. .. 3 .. 1,560 1,094 91,323 .. 85 19,860 4,905 .. .. 7 44 356,636 21,095 241,547 711 47 1,215 121,569 .. 44 542 286 1,080 17,658 .. 15,377 .. 20,453 .. 10 .. 129 5 .. .. 174 73,783 45 38 7,222 34,925 17,787 .. 174 883 6 1,185 34,583 .. .. 182 15,187 25,521
1990 1990005 Less developed regions, excluding least developed countries 934 27,448,095 401,994 1,174,731 3,013,479 1,024 25,021 470 21 20,494 718 3,970 104,776 129,771 3,235 26,392 17,714 325,806 920 5,882 2,220,300 2,608 106,682 13,255 2,130 80,558 73 5,599 87,429 3,370 5,117 104,812 1,680 7,436 255,128 425,191 1,044 164 51,533 14,790 28,607 754 53 5,042 63,384 67 142,702 1,180,087 17,033 39,710 343,157 4,598 4,656 28 11,742 3,851 1,774 29,501 1,546 5,480 4,822 12,580 44,716 3,645 355 10,696 45,248 24,208 374,609 383,059 13,858 3,790 2,108 56,929 2 12 1,894 2,232 138,770 1,563 1,367 703 5,005 63,533 422,809 96,626 36 78,781 326 10,613 3,157 661 51,127 62,271 718 14,009 84,245 13 23,717 14,798 46 1,961,149 492,064 52,845 590,159 4,422 .. 61,759 269,639 8,119 77,251 105,006 78,807 6,239 1,000 28,433 21,405 93,514 7,936 51,681 43,756 9,727 23,196 66 16,693 236 2,553 32,936 147,305 354 203,403 144 151 5,274 3,413 3,758 849 24,031 2,367 158 79 124 1,061 89,968 332,275 166,436 4,650 16 351,520 32,079 1,327 7,867 128,934 29,496 75,916 19 1,183 1,868 5,787 1,178,463 1,583 22,065 59 157,753 38,043 357,097 101,491 181,069 9,478 5,749 112,325 31,377 1,005 82,845 2,857,946 3,458 242 5,816 6,438 23 10,140 7,356 7 2,553 35,610 11,810 1,977 103 1,382 28,465 237 255 1,059 449 10,312 30,501 6,601 263,469 315,506 906,816 123,204 9,304 9,268 4,190 17,604 214,957 12,874 25,484 38,047 262 69,886 80 1,230 7,672 24,736 41,453 5,963 1,191 352 45,174 483,995 32,423 161,973 31,892 399,467 1,156 90,636 184,777 1,852 35,491 38,988 2,679 75,516 160,824 13,947 39,466
1990 1990006 High-income countries e 1503 36,450,724 560,571 1,734,535 97,474 42,266 375,784 34 2,005 86,410 658 10,857 160,453 37,179 2,870 141,111 253,472 16,277 14,108 1,229 231,790 43,733 212,647 196,305 18,977 5,951 36,958 164 25,481 242,658 1,222 176,790 1,703 3,283 50,751 2,409 1,761 43,270 122,147 24,909 609,895 1,597 146 4,357 9,374 9,907 102,481 1,622,567 275,790 41,766 211,427 9,641 25,812 9,085 29,040 24,703 179,640 415,454 19,270 77,838 134,381 2,401 28,043 105,972 1,622 17,505 244,054 85,260 388,816 250,709 3,957 15,334 17,934 99,664 4,532 110 44,311 145,730 499,255 36 1,515 4,385 4,042 40,739 1,291,107 53,029 6,290 396,173 5,413 22,866 106 637 119,692 5,883 6,340 115,227 154,508 18 66,678 171,502 8,944 1,164,589 539,314 237,699 117,223 500,089 5,637 76,122 1,373,772 318,290 233,762 81,720 29,928 75,492 545 14,414 3,821 124,854 46,213 186,131 190 8,236 20,814 1,918 112,201 13,811 24,856 5,570 226,153 73 17,821 53,806 666 164 3,859 53,901 .. 2,015,051 3,738 1,940 1,641 26,488 3,742 674,573 40,985 52,631 606 248 49,138 339,094 1,649 184,942 93,760 1,291 59,219 3,011 1,140 74,293 284 452,046 1,427 47,230 880 9,064 129,669 1,116,578 748,798 727,966 618,322 506 700,946 31,132 61 419,032 934,017 3,099 256 9,552 9,967 222 18,630 30,899 824 3,109 18,436 35,868 312,018 15,156 8,329 52,416 6,863 64,095 28,608 585 33,538 121,117 1,860 520,452 263,745 26,116 97,217 83,216 281 114,983 162,837 194,130 4,753 176,196 149,257 5,078 7,872 768 15,229 105,320 177,014 1,189,294 21,236 1,305 605 34,681 553,801 21,617 1,786,609 29,620 628,061 821 32,754 33,135 2,068 69,885 508,076 2,814 12 154,903 12,865 21,147
migrantFemaleDF$Gender <- "Female"
## Merge into one data frame
migrantDF <- tbl_df(rbind(migrantMaleDF,migrantFemaleDF))
head(migrantDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Year Sort.order Major.area..region..country.or.area.of.destination Notes Code Type.of.data..a. Total Other.North Other.South Afghanistan Albania Algeria American.Samoa Andorra Angola Anguilla Antigua.and.Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia..Plurinational.State.of. Bosnia.and.Herzegovina Botswana Brazil British.Virgin.Islands Brunei.Darussalam Bulgaria Burkina.Faso Burundi Cabo.Verde Cambodia Cameroon Canada Caribbean.Netherlands Cayman.Islands Central.African.Republic Chad Channel.Islands Chile China China..Hong.Kong.SAR China..Macao.SAR Colombia Comoros Congo Cook.Islands Costa.Rica Côte.d.Ivoire Croatia Cuba Curaçao Cyprus Czechia Dem..People.s.Republic.of.Korea Democratic.Republic.of.the.Congo Denmark Djibouti Dominica Dominican.Republic Ecuador Egypt El.Salvador Equatorial.Guinea Eritrea Estonia Ethiopia Faeroe.Islands Falkland.Islands..Malvinas. Fiji Finland France French.Guiana French.Polynesia Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guinea Guinea.Bissau Guyana Haiti Holy.See Honduras Hungary Iceland India Indonesia Iran..Islamic.Republic.of. Iraq Ireland Isle.of.Man Israel Italy Jamaica Japan Jordan Kazakhstan Kenya Kiribati Kuwait Kyrgyzstan Lao.People.s.Democratic.Republic Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Madagascar Malawi Malaysia Maldives Mali Malta Marshall.Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia..Fed..States.of. Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands New.Caledonia New.Zealand Nicaragua Niger Nigeria Niue Northern.Mariana.Islands Norway Oman Pakistan Palau Panama Papua.New.Guinea Paraguay Peru Philippines Poland Portugal Puerto.Rico Qatar Republic.of.Korea Republic.of.Moldova Réunion Romania Russian.Federation Rwanda Saint.Helena Saint.Kitts.and.Nevis Saint.Lucia Saint.Pierre.and.Miquelon Saint.Vincent.and.the.Grenadines Samoa San.Marino Sao.Tome.and.Principe Saudi.Arabia Senegal Serbia Seychelles Sierra.Leone Singapore Sint.Maarten..Dutch.part. Slovakia Slovenia Solomon.Islands Somalia South.Africa South.Sudan Spain Sri.Lanka State.of.Palestine Sudan Suriname Swaziland Sweden Switzerland Syrian.Arab.Republic Tajikistan TFYR.Macedonia Thailand Timor.Leste Togo Tokelau Tonga Trinidad.and.Tobago Tunisia Turkey Turkmenistan Turks.and.Caicos.Islands Tuvalu Uganda Ukraine United.Arab.Emirates United.Kingdom United.Republic.of.Tanzania United.States.of.America United.States.Virgin.Islands Uruguay Uzbekistan Vanuatu Venezuela..Bolivarian.Republic.of. Viet.Nam Wallis.and.Futuna.Islands Western.Sahara Yemen Zambia Zimbabwe Gender
1990 1990001 WORLD 900 77,456,347 1,060,798 3,322,039 3,661,547 109,056 512,243 1,049 1,769 397,396 1,069 9,812 203,688 436,884 4,742 140,585 234,591 767,243 10,622 6,067 3,162,730 40,152 816,810 157,228 15,090 126,799 34,703 13,863 115,457 428,195 19,227 226,262 1,340 15,605 302,345 571,852 174,024 42,805 174,414 59,783 366,550 2,165 192 24,146 168,156 8,755 246,732 2,198,341 272,012 48,482 458,549 22,058 48,201 8,377 29,265 188,007 214,453 399,117 21,274 90,730 130,392 18,753 199,663 91,877 2,876 19,272 198,326 105,553 822,199 608,502 16,940 89,624 54,329 854,717 2,992 141 43,625 101,880 566,452 1,253 1,595 7,661 20,713 446,549 1,503,513 188,537 5,671 542,735 3,774 19,604 2,590 694 173,120 201,470 27,391 110,776 294,362 14 66,894 191,820 8,633 3,857,101 951,535 361,354 854,938 413,377 5,098 137,827 1,779,050 268,141 301,582 187,244 1,427,024 118,536 1,937 45,161 252,656 236,885 99,955 290,900 146,090 260,528 39,985 1,448 152,616 13,734 25,385 71,829 276,624 1,698 360,704 56,493 708 5,609 74,892 50,677 986 2,357,870 3,935 2,213 11,630 39,492 3,366 902,650 1,200,919 376,096 9,351 626 389,287 363,337 1,928 196,149 219,783 84,774 256,747 2,832 1,204 59,890 6,450 1,970,220 1,369 66,554 1,509 131,618 149,880 834,460 717,210 969,080 574,866 6,028 815,465 290,663 1,571 377,026 5,521,935 278,431 386 9,534 10,053 240 17,900 36,602 569 6,725 57,708 230,217 375,377 14,033 31,381 74,426 7,331 66,110 40,067 1,134 448,139 160,035 266,794 690,938 458,991 888,313 336,705 87,491 25,591 87,956 143,912 354,953 263,716 215,990 122,347 5,921 95,160 836 16,197 87,603 273,859 1,308,220 127,448 1,006 1,203 157,808 2,636,852 44,694 1,876,977 107,733 868,212 1,175 116,376 686,783 2,646 83,042 635,164 3,664 92,655 290,279 41,050 90,471 Male
1990 1990002 More developed regions b 901 40,270,398 522,085 1,826,518 69,683 107,782 485,698 505 1,735 80,074 280 6,590 100,790 321,121 2,020 109,138 218,189 515,511 9,735 952 93,050 37,391 726,178 143,609 13,285 8,080 34,623 291 20,940 424,148 1,508 113,992 84 3,341 62,989 3,516 1,911 36,603 114,437 24,378 336,361 1,437 141 4,573 2,069 8,720 87,562 722,857 254,737 6,926 156,772 9,291 30,326 8,358 19,472 24,168 212,521 368,021 19,613 85,819 126,417 7,202 32,812 88,180 1,818 11,345 165,967 80,987 158,971 257,128 3,319 12,913 52,698 57,044 2,992 130 41,695 100,427 388,602 29 137 4,187 8,511 392,338 1,107,340 73,007 5,633 471,068 3,587 10,793 81 22 121,197 8,442 9,503 97,918 144,509 6 48,330 179,268 8,589 633,811 150,279 301,290 85,814 409,455 5,098 87,313 1,487,482 262,398 204,564 48,780 1,368,060 78,678 444 8,428 234,526 126,221 93,411 206,659 178 9,953 14,070 1,336 138,557 13,606 17,817 5,994 92,037 163 33,313 56,391 548 158 9,079 45,387 .. 2,337,159 1,352 2,092 11,543 39,375 2,413 814,038 37,752 21,826 623 217 4,496 332,771 536 187,537 85,577 1,992 89,169 2,812 136 55,383 416 259,303 6 43,987 870 5,913 101,284 507,839 631,417 752,337 565,279 477 685,575 263,522 64 307,870 3,284,119 3,375 283 4,522 4,593 211 9,411 28,658 533 2,745 12,148 93,787 373,783 13,790 10,487 41,882 6,998 65,806 39,098 530 34,408 106,165 .. 432,631 148,713 18,881 9,433 77,305 268 82,964 123,661 75,462 229,236 189,945 70,479 5,436 10,867 755 14,745 80,657 249,632 1,258,096 122,637 107 550 36,292 2,243,566 3,210 1,714,045 31,189 434,712 39 26,490 521,086 461 48,465 556,402 743 265 7,250 12,896 19,593 Male
1990 1990003 Less developed regions c 902 37,185,949 538,713 1,495,521 3,591,864 1,274 26,545 544 34 317,322 789 3,222 102,898 115,763 2,722 31,447 16,402 251,732 887 5,115 3,069,680 2,761 90,632 13,619 1,805 118,719 80 13,572 94,517 4,047 17,719 112,270 1,256 12,264 239,356 568,336 172,113 6,202 59,977 35,405 30,189 728 51 19,573 166,087 35 159,170 1,475,484 17,275 41,556 301,777 12,767 17,875 19 9,793 163,839 1,932 31,096 1,661 4,911 3,975 11,551 166,851 3,697 1,058 7,927 32,359 24,566 663,228 351,374 13,621 76,711 1,631 797,673 .. 11 1,930 1,453 177,850 1,224 1,458 3,474 12,202 54,211 396,173 115,530 38 71,667 187 8,811 2,509 672 51,923 193,028 17,888 12,858 149,853 8 18,564 12,552 44 3,223,290 801,256 60,064 769,124 3,922 .. 50,514 291,568 5,743 97,018 138,464 58,964 39,858 1,493 36,733 18,130 110,664 6,544 84,241 145,912 250,575 25,915 112 14,059 128 7,568 65,835 184,587 1,535 327,391 102 160 5,451 65,813 5,290 986 20,711 2,583 121 87 117 953 88,612 1,163,167 354,270 8,728 409 384,791 30,566 1,392 8,612 134,206 82,782 167,578 20 1,068 4,507 6,034 1,710,917 1,363 22,567 639 125,705 48,596 326,621 85,793 216,743 9,587 5,551 129,890 27,141 1,507 69,156 2,237,816 275,056 103 5,012 5,460 29 8,489 7,944 36 3,980 45,560 136,430 1,594 243 20,894 32,544 333 304 969 604 413,731 53,870 266,794 258,307 310,278 869,432 327,272 10,186 25,323 4,992 20,251 279,491 34,480 26,045 51,868 485 84,293 81 1,452 6,946 24,227 50,124 4,811 899 653 121,516 393,286 41,484 162,932 76,544 433,500 1,136 89,886 165,697 2,185 34,577 78,762 2,921 92,390 283,029 28,154 70,878 Male
1990 1990004 Least developed countries d 941 5,556,516 141,569 272,883 .. .. 2,474 .. .. 288,361 .. .. 296 .. .. 809 155 .. .. 49 1,286 .. .. 503 .. 21,560 .. 8,065 .. .. 278 843 .. .. .. 21,746 170,263 6,021 7,676 17,913 978 .. .. 13,807 104,440 .. 214 129,816 31 .. 421 4,777 12,930 .. 106 159,061 .. 743 .. 3 .. 60 127,783 109 475 .. 1,345 .. 16,060 .. 152 69,934 .. 714,497 .. .. 376 .. 20,194 .. .. 2,815 6,647 .. 2,568 27,607 .. 21 .. .. .. .. .. 118,202 16,933 .. .. .. .. .. .. 158,366 40,346 .. 2,776 .. .. .. 1,709 .. 5,326 .. .. 33,312 483 9 .. 31,777 .. 4,498 1,648 239,503 1,934 .. .. .. 5,007 15,533 50,228 .. 66,996 .. .. .. 55,794 70 .. 131 .. .. .. .. .. 1,778 621,383 106,389 1,683 399 5,453 300 128 271 .. 21,865 59,176 .. .. 2,290 .. 10,703 .. .. 592 .. 208 476 .. 7,993 703 .. 171 .. 507 .. 776 271,618 .. .. .. .. .. 18 .. 1,659 1,038 104,773 .. 129 19,179 5,773 .. .. 8 39 400,799 21,362 257,061 1,069 68 1,482 125,226 .. 58 599 400 1,313 22,879 .. 16,699 .. 12,586 .. 14 .. 92 1 .. .. 203 75,525 39 24 8,575 39,091 20,547 .. 112 1,144 3 1,325 36,996 .. .. 175 10,213 22,057 Male
1990 1990005 Less developed regions, excluding least developed countries 934 31,629,433 397,144 1,222,638 3,591,864 1,274 24,071 544 34 28,961 789 3,222 102,602 115,763 2,722 30,638 16,247 251,732 887 5,066 3,068,394 2,761 90,632 13,116 1,805 97,159 80 5,507 94,517 4,047 17,441 111,427 1,256 12,264 239,356 546,590 1,850 181 52,301 17,492 29,211 728 51 5,766 61,647 35 158,956 1,345,668 17,244 41,556 301,356 7,990 4,945 19 9,687 4,778 1,932 30,353 1,661 4,908 3,975 11,491 39,068 3,588 583 7,927 31,014 24,566 647,168 351,374 13,469 6,777 1,631 83,176 .. 11 1,554 1,453 157,656 1,224 1,458 659 5,555 54,211 393,605 87,923 38 71,646 187 8,811 2,509 672 51,923 74,826 955 12,858 149,853 8 18,564 12,552 44 3,064,924 760,910 60,064 766,348 3,922 .. 50,514 289,859 5,743 91,692 138,464 58,964 6,546 1,010 36,724 18,130 78,887 6,544 79,743 144,264 11,072 23,981 112 14,059 128 2,561 50,302 134,359 1,535 260,395 102 160 5,451 10,019 5,220 986 20,580 2,583 121 87 117 953 86,834 541,784 247,881 7,045 10 379,338 30,266 1,264 8,341 134,206 60,917 108,402 20 1,068 2,217 6,034 1,700,214 1,363 22,567 47 125,705 48,388 326,145 85,793 208,750 8,884 5,551 129,719 27,141 1,000 69,156 2,237,040 3,438 103 5,012 5,460 29 8,489 7,926 36 2,321 44,522 31,657 1,594 114 1,715 26,771 333 304 961 565 12,932 32,508 9,733 257,238 310,210 867,950 202,046 10,186 25,265 4,393 19,851 278,178 11,601 26,045 35,169 485 71,707 81 1,438 6,946 24,135 50,123 4,811 899 450 45,991 393,247 41,460 154,357 37,453 412,953 1,136 89,774 164,553 2,182 33,252 41,766 2,921 92,390 282,854 17,941 48,821 Male
1990 1990006 High-income countries e 1503 38,788,286 568,557 2,015,506 172,391 88,240 494,912 34 1,742 79,820 706 8,910 135,200 39,004 2,243 115,779 218,278 17,270 10,235 1,110 806,820 39,175 165,636 145,164 13,368 7,924 34,667 294 24,256 253,126 1,411 125,743 1,276 3,341 53,956 3,256 1,834 36,577 114,559 24,033 345,131 1,633 149 4,516 6,525 8,723 89,439 1,771,430 268,157 41,624 160,132 9,285 30,077 8,358 19,959 24,120 184,504 376,584 19,853 85,520 119,084 2,605 32,898 87,369 1,817 15,809 183,987 82,108 600,096 257,487 3,307 18,386 15,829 122,153 2,992 132 41,709 99,094 421,021 31 1,553 4,190 8,510 44,697 1,050,836 72,893 5,634 454,033 3,589 19,050 104 621 121,517 8,227 9,337 102,791 152,881 14 49,008 173,509 8,578 2,056,251 723,130 320,736 143,591 409,774 5,098 84,195 1,491,802 265,887 214,048 139,233 28,741 78,514 443 22,722 3,337 126,425 37,029 252,694 184 9,958 23,174 1,336 85,220 13,563 17,754 5,989 207,065 97 33,221 56,117 636 162 9,085 45,382 .. 2,339,382 3,875 1,999 1,156 28,919 3,229 891,936 37,705 81,264 572 217 149,078 337,705 1,367 189,322 85,950 1,985 90,811 2,812 1,000 54,858 415 912,063 1,150 45,045 872 7,183 105,451 760,588 659,668 754,496 567,895 458 689,508 30,447 64 363,209 762,161 3,288 283 8,212 8,042 213 17,374 28,658 522 2,751 21,410 93,745 357,778 13,791 10,489 45,959 7,068 62,985 26,550 530 37,784 110,843 3,222 457,753 307,243 36,518 170,018 77,690 269 83,360 125,046 263,535 4,795 178,181 83,203 5,436 10,868 755 14,746 83,224 270,639 1,272,725 25,021 1,002 533 36,256 460,186 31,152 1,756,615 31,083 615,513 746 29,017 32,571 2,290 51,932 535,732 3,658 211 275,071 12,733 19,497 Male
glimpse(migrantDF)
## Observations: 3,780
## Variables: 242
## $ Year                                               <int> 1990, 1990,...
## $ Sort.order                                         <int> 1990001, 19...
## $ Major.area..region..country.or.area.of.destination <chr> "WORLD", "M...
## $ Notes                                              <chr> "", "b", "c...
## $ Code                                               <int> 900, 901, 9...
## $ Type.of.data..a.                                   <chr> "", "", "",...
## $ Total                                              <chr> "77,456,347...
## $ Other.North                                        <chr> "1,060,798"...
## $ Other.South                                        <chr> "3,322,039"...
## $ Afghanistan                                        <chr> "3,661,547"...
## $ Albania                                            <chr> "109,056", ...
## $ Algeria                                            <chr> "512,243", ...
## $ American.Samoa                                     <chr> "1,049", "5...
## $ Andorra                                            <chr> "1,769", "1...
## $ Angola                                             <chr> "397,396", ...
## $ Anguilla                                           <chr> "1,069", "2...
## $ Antigua.and.Barbuda                                <chr> "9,812", "6...
## $ Argentina                                          <chr> "203,688", ...
## $ Armenia                                            <chr> "436,884", ...
## $ Aruba                                              <chr> "4,742", "2...
## $ Australia                                          <chr> "140,585", ...
## $ Austria                                            <chr> "234,591", ...
## $ Azerbaijan                                         <chr> "767,243", ...
## $ Bahamas                                            <chr> "10,622", "...
## $ Bahrain                                            <chr> "6,067", "9...
## $ Bangladesh                                         <chr> "3,162,730"...
## $ Barbados                                           <chr> "40,152", "...
## $ Belarus                                            <chr> "816,810", ...
## $ Belgium                                            <chr> "157,228", ...
## $ Belize                                             <chr> "15,090", "...
## $ Benin                                              <chr> "126,799", ...
## $ Bermuda                                            <chr> "34,703", "...
## $ Bhutan                                             <chr> "13,863", "...
## $ Bolivia..Plurinational.State.of.                   <chr> "115,457", ...
## $ Bosnia.and.Herzegovina                             <chr> "428,195", ...
## $ Botswana                                           <chr> "19,227", "...
## $ Brazil                                             <chr> "226,262", ...
## $ British.Virgin.Islands                             <chr> "1,340", "8...
## $ Brunei.Darussalam                                  <chr> "15,605", "...
## $ Bulgaria                                           <chr> "302,345", ...
## $ Burkina.Faso                                       <chr> "571,852", ...
## $ Burundi                                            <chr> "174,024", ...
## $ Cabo.Verde                                         <chr> "42,805", "...
## $ Cambodia                                           <chr> "174,414", ...
## $ Cameroon                                           <chr> "59,783", "...
## $ Canada                                             <chr> "366,550", ...
## $ Caribbean.Netherlands                              <chr> "2,165", "1...
## $ Cayman.Islands                                     <chr> "192", "141...
## $ Central.African.Republic                           <chr> "24,146", "...
## $ Chad                                               <chr> "168,156", ...
## $ Channel.Islands                                    <chr> "8,755", "8...
## $ Chile                                              <chr> "246,732", ...
## $ China                                              <chr> "2,198,341"...
## $ China..Hong.Kong.SAR                               <chr> "272,012", ...
## $ China..Macao.SAR                                   <chr> "48,482", "...
## $ Colombia                                           <chr> "458,549", ...
## $ Comoros                                            <chr> "22,058", "...
## $ Congo                                              <chr> "48,201", "...
## $ Cook.Islands                                       <chr> "8,377", "8...
## $ Costa.Rica                                         <chr> "29,265", "...
## $ Côte.d.Ivoire                                      <chr> "188,007", ...
## $ Croatia                                            <chr> "214,453", ...
## $ Cuba                                               <chr> "399,117", ...
## $ Curaçao                                            <chr> "21,274", "...
## $ Cyprus                                             <chr> "90,730", "...
## $ Czechia                                            <chr> "130,392", ...
## $ Dem..People.s.Republic.of.Korea                    <chr> "18,753", "...
## $ Democratic.Republic.of.the.Congo                   <chr> "199,663", ...
## $ Denmark                                            <chr> "91,877", "...
## $ Djibouti                                           <chr> "2,876", "1...
## $ Dominica                                           <chr> "19,272", "...
## $ Dominican.Republic                                 <chr> "198,326", ...
## $ Ecuador                                            <chr> "105,553", ...
## $ Egypt                                              <chr> "822,199", ...
## $ El.Salvador                                        <chr> "608,502", ...
## $ Equatorial.Guinea                                  <chr> "16,940", "...
## $ Eritrea                                            <chr> "89,624", "...
## $ Estonia                                            <chr> "54,329", "...
## $ Ethiopia                                           <chr> "854,717", ...
## $ Faeroe.Islands                                     <chr> "2,992", "2...
## $ Falkland.Islands..Malvinas.                        <chr> "141", "130...
## $ Fiji                                               <chr> "43,625", "...
## $ Finland                                            <chr> "101,880", ...
## $ France                                             <chr> "566,452", ...
## $ French.Guiana                                      <chr> "1,253", "2...
## $ French.Polynesia                                   <chr> "1,595", "1...
## $ Gabon                                              <chr> "7,661", "4...
## $ Gambia                                             <chr> "20,713", "...
## $ Georgia                                            <chr> "446,549", ...
## $ Germany                                            <chr> "1,503,513"...
## $ Ghana                                              <chr> "188,537", ...
## $ Gibraltar                                          <chr> "5,671", "5...
## $ Greece                                             <chr> "542,735", ...
## $ Greenland                                          <chr> "3,774", "3...
## $ Grenada                                            <chr> "19,604", "...
## $ Guadeloupe                                         <chr> "2,590", "8...
## $ Guam                                               <chr> "694", "22"...
## $ Guatemala                                          <chr> "173,120", ...
## $ Guinea                                             <chr> "201,470", ...
## $ Guinea.Bissau                                      <chr> "27,391", "...
## $ Guyana                                             <chr> "110,776", ...
## $ Haiti                                              <chr> "294,362", ...
## $ Holy.See                                           <chr> "14", "6", ...
## $ Honduras                                           <chr> "66,894", "...
## $ Hungary                                            <chr> "191,820", ...
## $ Iceland                                            <chr> "8,633", "8...
## $ India                                              <chr> "3,857,101"...
## $ Indonesia                                          <chr> "951,535", ...
## $ Iran..Islamic.Republic.of.                         <chr> "361,354", ...
## $ Iraq                                               <chr> "854,938", ...
## $ Ireland                                            <chr> "413,377", ...
## $ Isle.of.Man                                        <chr> "5,098", "5...
## $ Israel                                             <chr> "137,827", ...
## $ Italy                                              <chr> "1,779,050"...
## $ Jamaica                                            <chr> "268,141", ...
## $ Japan                                              <chr> "301,582", ...
## $ Jordan                                             <chr> "187,244", ...
## $ Kazakhstan                                         <chr> "1,427,024"...
## $ Kenya                                              <chr> "118,536", ...
## $ Kiribati                                           <chr> "1,937", "4...
## $ Kuwait                                             <chr> "45,161", "...
## $ Kyrgyzstan                                         <chr> "252,656", ...
## $ Lao.People.s.Democratic.Republic                   <chr> "236,885", ...
## $ Latvia                                             <chr> "99,955", "...
## $ Lebanon                                            <chr> "290,900", ...
## $ Lesotho                                            <chr> "146,090", ...
## $ Liberia                                            <chr> "260,528", ...
## $ Libya                                              <chr> "39,985", "...
## $ Liechtenstein                                      <chr> "1,448", "1...
## $ Lithuania                                          <chr> "152,616", ...
## $ Luxembourg                                         <chr> "13,734", "...
## $ Madagascar                                         <chr> "25,385", "...
## $ Malawi                                             <chr> "71,829", "...
## $ Malaysia                                           <chr> "276,624", ...
## $ Maldives                                           <chr> "1,698", "1...
## $ Mali                                               <chr> "360,704", ...
## $ Malta                                              <chr> "56,493", "...
## $ Marshall.Islands                                   <chr> "708", "548...
## $ Martinique                                         <chr> "5,609", "1...
## $ Mauritania                                         <chr> "74,892", "...
## $ Mauritius                                          <chr> "50,677", "...
## $ Mayotte                                            <chr> "986", ".."...
## $ Mexico                                             <chr> "2,357,870"...
## $ Micronesia..Fed..States.of.                        <chr> "3,935", "1...
## $ Monaco                                             <chr> "2,213", "2...
## $ Mongolia                                           <chr> "11,630", "...
## $ Montenegro                                         <chr> "39,492", "...
## $ Montserrat                                         <chr> "3,366", "2...
## $ Morocco                                            <chr> "902,650", ...
## $ Mozambique                                         <chr> "1,200,919"...
## $ Myanmar                                            <chr> "376,096", ...
## $ Namibia                                            <chr> "9,351", "6...
## $ Nauru                                              <chr> "626", "217...
## $ Nepal                                              <chr> "389,287", ...
## $ Netherlands                                        <chr> "363,337", ...
## $ New.Caledonia                                      <chr> "1,928", "5...
## $ New.Zealand                                        <chr> "196,149", ...
## $ Nicaragua                                          <chr> "219,783", ...
## $ Niger                                              <chr> "84,774", "...
## $ Nigeria                                            <chr> "256,747", ...
## $ Niue                                               <chr> "2,832", "2...
## $ Northern.Mariana.Islands                           <chr> "1,204", "1...
## $ Norway                                             <chr> "59,890", "...
## $ Oman                                               <chr> "6,450", "4...
## $ Pakistan                                           <chr> "1,970,220"...
## $ Palau                                              <chr> "1,369", "6...
## $ Panama                                             <chr> "66,554", "...
## $ Papua.New.Guinea                                   <chr> "1,509", "8...
## $ Paraguay                                           <chr> "131,618", ...
## $ Peru                                               <chr> "149,880", ...
## $ Philippines                                        <chr> "834,460", ...
## $ Poland                                             <chr> "717,210", ...
## $ Portugal                                           <chr> "969,080", ...
## $ Puerto.Rico                                        <chr> "574,866", ...
## $ Qatar                                              <chr> "6,028", "4...
## $ Republic.of.Korea                                  <chr> "815,465", ...
## $ Republic.of.Moldova                                <chr> "290,663", ...
## $ Réunion                                            <chr> "1,571", "6...
## $ Romania                                            <chr> "377,026", ...
## $ Russian.Federation                                 <chr> "5,521,935"...
## $ Rwanda                                             <chr> "278,431", ...
## $ Saint.Helena                                       <chr> "386", "283...
## $ Saint.Kitts.and.Nevis                              <chr> "9,534", "4...
## $ Saint.Lucia                                        <chr> "10,053", "...
## $ Saint.Pierre.and.Miquelon                          <chr> "240", "211...
## $ Saint.Vincent.and.the.Grenadines                   <chr> "17,900", "...
## $ Samoa                                              <chr> "36,602", "...
## $ San.Marino                                         <chr> "569", "533...
## $ Sao.Tome.and.Principe                              <chr> "6,725", "2...
## $ Saudi.Arabia                                       <chr> "57,708", "...
## $ Senegal                                            <chr> "230,217", ...
## $ Serbia                                             <chr> "375,377", ...
## $ Seychelles                                         <chr> "14,033", "...
## $ Sierra.Leone                                       <chr> "31,381", "...
## $ Singapore                                          <chr> "74,426", "...
## $ Sint.Maarten..Dutch.part.                          <chr> "7,331", "6...
## $ Slovakia                                           <chr> "66,110", "...
## $ Slovenia                                           <chr> "40,067", "...
## $ Solomon.Islands                                    <chr> "1,134", "5...
## $ Somalia                                            <chr> "448,139", ...
## $ South.Africa                                       <chr> "160,035", ...
## $ South.Sudan                                        <chr> "266,794", ...
## $ Spain                                              <chr> "690,938", ...
## $ Sri.Lanka                                          <chr> "458,991", ...
## $ State.of.Palestine                                 <chr> "888,313", ...
## $ Sudan                                              <chr> "336,705", ...
## $ Suriname                                           <chr> "87,491", "...
## $ Swaziland                                          <chr> "25,591", "...
## $ Sweden                                             <chr> "87,956", "...
## $ Switzerland                                        <chr> "143,912", ...
## $ Syrian.Arab.Republic                               <chr> "354,953", ...
## $ Tajikistan                                         <chr> "263,716", ...
## $ TFYR.Macedonia                                     <chr> "215,990", ...
## $ Thailand                                           <chr> "122,347", ...
## $ Timor.Leste                                        <chr> "5,921", "5...
## $ Togo                                               <chr> "95,160", "...
## $ Tokelau                                            <chr> "836", "755...
## $ Tonga                                              <chr> "16,197", "...
## $ Trinidad.and.Tobago                                <chr> "87,603", "...
## $ Tunisia                                            <chr> "273,859", ...
## $ Turkey                                             <chr> "1,308,220"...
## $ Turkmenistan                                       <chr> "127,448", ...
## $ Turks.and.Caicos.Islands                           <chr> "1,006", "1...
## $ Tuvalu                                             <chr> "1,203", "5...
## $ Uganda                                             <chr> "157,808", ...
## $ Ukraine                                            <chr> "2,636,852"...
## $ United.Arab.Emirates                               <chr> "44,694", "...
## $ United.Kingdom                                     <chr> "1,876,977"...
## $ United.Republic.of.Tanzania                        <chr> "107,733", ...
## $ United.States.of.America                           <chr> "868,212", ...
## $ United.States.Virgin.Islands                       <chr> "1,175", "3...
## $ Uruguay                                            <chr> "116,376", ...
## $ Uzbekistan                                         <chr> "686,783", ...
## $ Vanuatu                                            <chr> "2,646", "4...
## $ Venezuela..Bolivarian.Republic.of.                 <chr> "83,042", "...
## $ Viet.Nam                                           <chr> "635,164", ...
## $ Wallis.and.Futuna.Islands                          <chr> "3,664", "7...
## $ Western.Sahara                                     <chr> "92,655", "...
## $ Yemen                                              <chr> "290,279", ...
## $ Zambia                                             <chr> "41,050", "...
## $ Zimbabwe                                           <chr> "90,471", "...
## $ Gender                                             <chr> "Male", "Ma...
### Country to Continenet Map
countryDF <- read.delim("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-607/Tidy%20Data%20Project/Source%20Data/UNCountryContinentMap.csv",header = TRUE, stringsAsFactors = FALSE, sep = ",")
  1. Clean the data set:

First few records in the 2nd column (Country of destination) of the data set represents regions, Continents etc. These records need to be stripped of as part of data cleansing. For all these records, 5h column (Type of Data) is populated with BLANK values.

Also removed the unnecessary columns from the data set not required for further analysis -

## Clean up the unnecessary rows 
migrantDF <- migrantDF %>% filter(Type.of.data..a.!= "")

## Remove unnecessary columns
migrantDF <- migrantDF %>% select(-Sort.order,-Notes,-Code,-Type.of.data..a., -Total,-Other.North,-Other.South)
names(migrantDF)[2] <- "destination_country"
head(migrantDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Year destination_country Afghanistan Albania Algeria American.Samoa Andorra Angola Anguilla Antigua.and.Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia..Plurinational.State.of. Bosnia.and.Herzegovina Botswana Brazil British.Virgin.Islands Brunei.Darussalam Bulgaria Burkina.Faso Burundi Cabo.Verde Cambodia Cameroon Canada Caribbean.Netherlands Cayman.Islands Central.African.Republic Chad Channel.Islands Chile China China..Hong.Kong.SAR China..Macao.SAR Colombia Comoros Congo Cook.Islands Costa.Rica Côte.d.Ivoire Croatia Cuba Curaçao Cyprus Czechia Dem..People.s.Republic.of.Korea Democratic.Republic.of.the.Congo Denmark Djibouti Dominica Dominican.Republic Ecuador Egypt El.Salvador Equatorial.Guinea Eritrea Estonia Ethiopia Faeroe.Islands Falkland.Islands..Malvinas. Fiji Finland France French.Guiana French.Polynesia Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guinea Guinea.Bissau Guyana Haiti Holy.See Honduras Hungary Iceland India Indonesia Iran..Islamic.Republic.of. Iraq Ireland Isle.of.Man Israel Italy Jamaica Japan Jordan Kazakhstan Kenya Kiribati Kuwait Kyrgyzstan Lao.People.s.Democratic.Republic Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Madagascar Malawi Malaysia Maldives Mali Malta Marshall.Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia..Fed..States.of. Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands New.Caledonia New.Zealand Nicaragua Niger Nigeria Niue Northern.Mariana.Islands Norway Oman Pakistan Palau Panama Papua.New.Guinea Paraguay Peru Philippines Poland Portugal Puerto.Rico Qatar Republic.of.Korea Republic.of.Moldova Réunion Romania Russian.Federation Rwanda Saint.Helena Saint.Kitts.and.Nevis Saint.Lucia Saint.Pierre.and.Miquelon Saint.Vincent.and.the.Grenadines Samoa San.Marino Sao.Tome.and.Principe Saudi.Arabia Senegal Serbia Seychelles Sierra.Leone Singapore Sint.Maarten..Dutch.part. Slovakia Slovenia Solomon.Islands Somalia South.Africa South.Sudan Spain Sri.Lanka State.of.Palestine Sudan Suriname Swaziland Sweden Switzerland Syrian.Arab.Republic Tajikistan TFYR.Macedonia Thailand Timor.Leste Togo Tokelau Tonga Trinidad.and.Tobago Tunisia Turkey Turkmenistan Turks.and.Caicos.Islands Tuvalu Uganda Ukraine United.Arab.Emirates United.Kingdom United.Republic.of.Tanzania United.States.of.America United.States.Virgin.Islands Uruguay Uzbekistan Vanuatu Venezuela..Bolivarian.Republic.of. Viet.Nam Wallis.and.Futuna.Islands Western.Sahara Yemen Zambia Zimbabwe Gender
1990 Burundi .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 315 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 17,963 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 157 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 104 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 108,772 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 898 .. .. .. 5,838 .. .. .. .. .. .. .. .. .. .. .. .. Male
1990 Comoros .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 310 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 40 .. .. .. .. .. .. .. .. .. .. .. .. 5,007 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 507 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 79 .. .. .. .. .. .. .. .. .. .. .. .. Male
1990 Djibouti .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 5,911 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 54,118 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 139 .. .. Male
1990 Eritrea .. .. .. .. .. 138 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 306 .. .. .. .. .. .. .. .. .. .. 2 .. .. .. 6 .. .. .. .. .. .. .. .. .. .. 235 .. .. .. .. .. .. .. .. .. .. 668 .. .. .. .. 52 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 22 .. .. .. .. .. .. .. .. .. .. .. 125 .. .. .. .. .. .. .. .. .. .. .. .. .. 39 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1,813 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 540 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 741 60 494 .. .. .. 69 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 109 .. .. 14 113 .. .. .. .. .. .. .. .. .. .. 57 56 Male
1990 Ethiopia .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 10 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 25 .. 475 .. .. .. .. .. .. 36,625 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 37 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 324,269 .. 201,974 .. .. .. 28,308 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 54 .. .. .. .. .. .. .. .. .. .. .. .. .. 36 .. .. Male
1990 Kenya .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 55 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 216 .. .. .. .. .. .. .. .. .. .. 15,293 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 580 .. 66 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 2,155 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 4,382 110 3,332 .. .. .. 467 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 42,091 .. .. .. 35,782 .. .. .. .. .. .. .. .. .. .. .. .. Male
  1. Use tidyr function gather() to unpivot Country of origin columns into a variable called ‘origin_country’ and replace ‘.’ character in ‘Destination’origin_country’ variable with a space character:
migrantDF <- migrantDF %>% gather(key = origin_country, value = "no_of_migrants", -Year, -destination_country, -Gender) 
migrantDF$origin_country <- str_replace_all(migrantDF$origin_country, "\\."," ")
migrantDF <- migrantDF %>% filter(no_of_migrants != "..")
migrantDF$no_of_migrants <- str_replace_all(migrantDF$no_of_migrants, "\\,","")
migrantDF$no_of_migrants <- as.numeric(migrantDF$no_of_migrants)
migrantDF <- migrantDF %>% filter(!is.na(no_of_migrants))

### Lookup and Tag Continenet attribute based on destination_country
migrantDF <- migrantDF %>% inner_join(countryDF, by = c("destination_country" = "Country"))

head(migrantDF)  %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Year destination_country Gender origin_country no_of_migrants Continent
1990 Egypt Male Afghanistan 194 Africa
1990 Libya Male Afghanistan 556 Africa
1990 Namibia Male Afghanistan 26 Africa
1990 South Africa Male Afghanistan 37 Africa
1990 Tajikistan Male Afghanistan 3726 Asia
1990 India Male Afghanistan 7259 Asia
  1. Analyze Data: Summarise the Migratnts data by destination continents to look at the trend of major destination targets for global immigrants.
migrantSummaryDF <- migrantDF %>% group_by(Year, Continent) %>% summarise(Migrant_Count = sum(no_of_migrants))  %>% mutate(Migrant_Count = Migrant_Count/1000000)

ggplot(migrantSummaryDF, aes(x = Continent, y = Migrant_Count, fill = as.character(Year))) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label=paste0(round(Migrant_Count,1),"M")), hjust=-0.5, color="black", position = position_dodge(1), size=3.5) +
  scale_fill_brewer(palette="Paired") +
  theme(axis.text.x=element_text(angle = 0, vjust = 0.5)) +
  theme(plot.title = element_text(hjust = 0.5), legend.position = "bottom") +
  ggtitle("Migration Trend By Major Destination Region (1990-2017)") +
  xlab("Year") +  ylab ("Migrant Count(in Millions)") + 
  coord_flip()

  1. Global Trend in Immigration in last few years:
migrantSummaryDF <- migrantDF %>% group_by(Year) %>% summarise(Migrant_Count = sum(no_of_migrants)) %>% mutate(Migrant_Count = Migrant_Count/1000000) 

#### National Avg. In-State 4 Year Fee Trend Analysis
ggplot(data=migrantSummaryDF, aes(x=Year,y= Migrant_Count, group=1)) +
  geom_line(arrow = arrow(), color = "black",size = 1.2)+
  geom_point(color = "red", size = 3)+
  theme(axis.text.x=element_text(angle = 0, vjust = 0.5)) +
  scale_fill_brewer(palette="Paired") + 
  ggtitle("Global Immigration Trend (1990-2017)") +
  theme(plot.title = element_text(hjust = 0.5)) +
  geom_text(aes(label=paste0(round(Migrant_Count,0),"M")), vjust=-1, color="black", position = position_dodge(0.9), size=3.5) 

  1. Below is a heatmap for 2017 Migrants stock between Origin and Destination countries after applying a filter to only include No. of Migrants > 1M.
migrantDF2017 <- migrantDF %>% filter(Year == "2017") %>% group_by(destination_country, origin_country) %>% summarise(Migrant_Count = sum(no_of_migrants))  %>% mutate(Migrant_Count = Migrant_Count/1000000)

migrantDF2017 <- migrantDF2017 %>% filter(Migrant_Count > 1)

ggplot(migrantDF2017, aes(y = origin_country, x = destination_country)) + 
        geom_tile(aes(fill = Migrant_Count),colour = "blue") +
        theme(axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5),
              panel.background = element_rect(fill = "darkblue",
                                colour = "darkblue",
                                size = 0.5, linetype = "solid"),
              panel.grid.major = element_line(size = 0.5, linetype = 'solid',
                                colour = "darkblue"), 
              panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
                                colour = "darkblue")) +
        theme(plot.title = element_text(hjust = 0.5)) +
        scale_fill_gradient(low = "blue", high = "darkred") +
        labs(fill="Migrant Count(in Millions)") +
        ggtitle("2017 Migrants Map Betweek Origina and Destination Countries") 

Conclusion:

In 2017, Mexico tops the chart in terms of no. of immigrants to US.

  1. Global distribution of Migrants in the year 2017:
WorldData <- map_data('world')
WorldData <- fortify(WorldData)

migrantDF2017 <- migrantDF %>% filter(Year == "2017") %>% group_by(destination_country) %>% summarise(Migrant_Count = sum(no_of_migrants)) %>% mutate(Migrant_Count = Migrant_Count/1000000)

ggplot() + 
  geom_map(data=WorldData, map=WorldData,
           aes(x=long, y=lat, group=group, map_id=region),
           fill="white", colour="#7f7f7f", size=0.5) + 
  geom_map(data=migrantDF2017, map=WorldData,
           aes(fill=Migrant_Count, map_id=destination_country),
           colour="#7f7f7f", size=0.5) + 
  coord_map("rectangular", lat0=0, xlim=c(-150,150), ylim=c(-60, 90)) + 
  scale_fill_continuous(low="thistle2", high="darkred", guide="colorbar") + 
  scale_y_continuous(breaks=c()) + 
  scale_x_continuous(breaks=c()) + 
  labs(fill="Migrant Count(in Millions)", title=element_text("Global View of the International Migrants - 2017",face = "bold", size = 20), x="", y="") + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme_bw() + 
  theme(panel.border = element_blank())
## Warning: Ignoring unknown aesthetics: x, y

  1. Finding Top 10 Migrants destinaton countries in 2017
migrantRankDF <- migrantDF %>% filter(Year == "2017") %>% group_by(destination_country) %>% summarise(Migrant_Count = sum(no_of_migrants)) %>% mutate(Migrant_Count = Migrant_Count/1000000) %>% mutate(rank = rank(-Migrant_Count)) %>% filter(rank <= 10) %>% arrange(rank)

ggplot(migrantRankDF, aes(x = reorder(destination_country,-Migrant_Count), y = Migrant_Count)) + 
  geom_bar(stat = "identity", position = "dodge", fill = "orange") + 
  geom_text(aes(label=paste0(round(Migrant_Count,1),"M")), vjust=-0.5, color="black", position = position_dodge(0.9), size=3.5) +
  scale_fill_brewer(palette="Paired") + 
  theme(axis.text.x=element_text(angle = 45, vjust = 0.5)) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Top 10 Migrant Destination Countries in 2017") +
  xlab("destination_country") +  ylab ("Migrant Count(in Millions)")

  1. Finding Top 10 Origin countries in 2017 contributing to global immigration community:
migrantOriginRankDF <- migrantDF %>% filter(Year == "2017") %>% group_by(origin_country) %>% summarise(Migrant_Count = sum(no_of_migrants)) %>% mutate(Migrant_Count = Migrant_Count/1000000) %>% mutate(rank = rank(-Migrant_Count)) %>% filter(rank <= 10) %>% arrange(rank)

ggplot(migrantOriginRankDF, aes(x = reorder(origin_country,-Migrant_Count), y = Migrant_Count)) + 
  geom_bar(stat = "identity", position = "dodge", fill = "steelblue") + 
  geom_text(aes(label=paste0(round(Migrant_Count,1),"M")), vjust=-0.5, color="black", position = position_dodge(0.9), size=3.5) +
  scale_fill_brewer(palette="Paired") + 
  theme(axis.text.x=element_text(angle = 45, vjust = 0.5)) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Top 10 Migrants Origin Countries in 2017") +
  xlab("Origin_Country") +  ylab ("Migrant Count(in Millions)")

Conclusion:

There is a steady significant increase in Global Immigration trend from various parts of the world to wards US due to better economic prosperity, quality of livelihood and increasing political unrest in certain parts of the world. US continues to be the most sought after destination for immigrants and India is at the top of the list as the origin of migrants due to it’s vast population.

Data Set 3: Untidy Dataset - Snack substitution

(USDA Stats) Snacks - impact on food costs and calorie intake of substituting fruits and vegetables for other snack foods.

Link to Data Source:

USDA WebSite - Calorie Impact Sheet

USDA WebSite - Cost Impact Sheet

Data Screen Shots:

Calorie Impact Data:

Note: A negative sign means that caloric intake increases when the snack is replaced with a fruit or vegetable.

Cost Impact Data:

Note: A negative sign means that food costs increase when the snack is replaced with a fruit or vegetable.

Below are the steps to be followed for extracting, cleansing and processing data to generate the final output -

  1. Convert the data sets into CSV fromat -

Both USDA Calorie and Cost Impact sheets for snack food substitution Excel Files are saved separately into two csv files.

  1. Import data into R:
## Calories Data
snackCalorieDF <- read.delim("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-607/Tidy%20Data%20Project/Source%20Data/caloricimpacts.csv",header = TRUE, stringsAsFactors = FALSE, sep = ",",skip = 1)

head(snackCalorieDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
X X.1 Apples Applesauce..sweetened. Bananas Cantaloupe Fruit.cocktail..in.light.syrup. Grapes Oranges Peaches..in.light.syrup. Pineapple..juice.pack. Plums Raisins Strawberries Tangerine Watermelon Broccoli Carrots Celery Red.Peppers Sweet.potatoes Tomatoes Average.change.in.calories.of.replacing.each.snack.with.all.fruits.and.vegetables X.2
Calories/ portion 77 100 102 33 71 59 53 68 75 38 109 27 72 74 12 22 10 23 90 16 NA NA
Chocolate candy (milk chocolate candies) 262 185 162 160 229 191 203 209 194 187 224 153 235 190 188 250 240 252 239 172 246 205 NA
Cookies (chocolate chip, soft) 123 46 23 21 90 52 64 70 55 48 85 14 96 51 49 111 101 113 100 33 107 66 NA
Corn chips 140 63 40 38 107 69 81 87 72 65 102 31 113 68 66 128 118 130 117 50 124 83 NA
Crackers (wheat) 114 37 14 12 81 43 55 61 46 39 76 5 87 42 40 102 92 104 91 24 98 57 NA
Cupcakes (chocolate, with low-fat frosting) 174 97 74 72 141 103 115 121 106 99 136 65 147 102 100 162 152 164 151 84 158 117 NA
## Cost Data
snackCostDF <- read.delim("https://raw.githubusercontent.com/soumya2g/R-CUNY-MSDS/master/DATA-607/Tidy%20Data%20Project/Source%20Data/costimpacts.csv",header = TRUE, stringsAsFactors = FALSE, sep = ",",skip = 1)

head(snackCostDF) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
X X.1 Apples Applesauce..jarred Bananas Cantaloupe Fruit.cocktail..canned Grapes Oranges Peaches..canned Pineapple..canned Plums Raisins Strawberries Tangerine Watermelon Broccoli Carrots Celery Red.peppers Sweet.potatoes..cooked Tomatoes..grape.or.cherry Total.cost.of.replacing.each.snack.with.all.fruits.and.vegetables X.2 X.3 X.4 X.5 X.6 X.7 X.8 X.9 X.10 X.11 X.12 X.13 X.14 X.15 X.16 X.17 X.18 X.19 X.20 X.21 X.22 X.23 X.24 X.25 X.26 X.27 X.28 X.29 X.30 X.31 X.32 X.33 X.34 X.35 X.36 X.37 X.38 X.39 X.40 X.41 X.42 X.43 X.44 X.45 X.46 X.47 X.48 X.49 X.50 X.51 X.52 X.53 X.54 X.55 X.56 X.57 X.58 X.59 X.60 X.61 X.62 X.63 X.64 X.65 X.66 X.67 X.68 X.69 X.70 X.71 X.72 X.73 X.74 X.75 X.76 X.77 X.78 X.79 X.80 X.81 X.82 X.83 X.84 X.85 X.86 X.87 X.88 X.89 X.90 X.91 X.92 X.93 X.94 X.95 X.96 X.97 X.98 X.99 X.100 X.101 X.102 X.103 X.104 X.105 X.106 X.107 X.108 X.109 X.110 X.111 X.112 X.113 X.114 X.115 X.116 X.117 X.118 X.119 X.120 X.121 X.122 X.123 X.124 X.125 X.126 X.127 X.128 X.129 X.130 X.131 X.132 X.133 X.134 X.135 X.136 X.137 X.138 X.139 X.140 X.141 X.142 X.143 X.144 X.145 X.146 X.147 X.148 X.149 X.150 X.151 X.152 X.153 X.154 X.155 X.156 X.157 X.158 X.159 X.160 X.161 X.162 X.163 X.164 X.165 X.166 X.167 X.168 X.169 X.170 X.171 X.172 X.173 X.174 X.175 X.176 X.177 X.178 X.179 X.180 X.181 X.182 X.183 X.184 X.185 X.186 X.187 X.188 X.189 X.190 X.191 X.192 X.193 X.194 X.195 X.196 X.197 X.198 X.199 X.200 X.201 X.202 X.203 X.204 X.205 X.206 X.207 X.208 X.209 X.210
price/portion 0.36 0.22 0.18 0.38 0.31 0.32 0.20 0.31 0.26 0.25 0.19 0.41 0.51 0.25 0.18 0.19 0.16 0.60 0.33 0.55 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Chocolate candy 0.24 -0.12 0.02 0.06 -0.14 -0.07 -0.08 0.04 -0.07 -0.02 -0.01 0.05 -0.17 -0.27 -0.01 0.06 0.05 0.08 -0.36 -0.09 -0.31 -1.36 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Cookies 0.16 -0.20 -0.06 -0.02 -0.22 -0.15 -0.16 -0.04 -0.15 -0.10 -0.09 -0.03 -0.25 -0.35 -0.09 -0.02 -0.03 0.00 -0.44 -0.17 -0.39 -2.96 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Corn chips 0.21 -0.15 -0.01 0.03 -0.17 -0.10 -0.11 0.01 -0.10 -0.05 -0.04 0.02 -0.20 -0.30 -0.04 0.03 0.02 0.05 -0.39 -0.12 -0.34 -1.96 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Crackers 0.16 -0.20 -0.06 -0.02 -0.22 -0.15 -0.16 -0.04 -0.15 -0.10 -0.09 -0.03 -0.25 -0.35 -0.09 -0.02 -0.03 0.00 -0.44 -0.17 -0.39 -2.96 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Cupcakes 0.34 -0.02 0.12 0.16 -0.04 0.03 0.02 0.14 0.03 0.08 0.09 0.15 -0.07 -0.17 0.09 0.16 0.15 0.18 -0.26 0.01 -0.21 0.64 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
  1. Clean the data set:

Remove the unnecessary rows and columns from the data set not required for further analysis -

A. USDA Calorie Data Cleanup:

## Clean up the unnecessary rows based on BALNK 1st column (Unhealthy Snacks)
snackCalorieDF <- snackCalorieDF %>% filter(X != "" & X.1 != "")

## Remove unnecessary columns
snackCalorieDF <- snackCalorieDF %>% select(-X.1, -X.2, -contains("Average"))
names(snackCalorieDF)[1] <- "Comfort_Snack"

snackCalorieDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Apples Applesauce..sweetened. Bananas Cantaloupe Fruit.cocktail..in.light.syrup. Grapes Oranges Peaches..in.light.syrup. Pineapple..juice.pack. Plums Raisins Strawberries Tangerine Watermelon Broccoli Carrots Celery Red.Peppers Sweet.potatoes Tomatoes
Chocolate candy (milk chocolate candies) 185 162 160 229 191 203 209 194 187 224 153 235 190 188 250 240 252 239 172 246
Cookies (chocolate chip, soft) 46 23 21 90 52 64 70 55 48 85 14 96 51 49 111 101 113 100 33 107
Corn chips 63 40 38 107 69 81 87 72 65 102 31 113 68 66 128 118 130 117 50 124
Crackers (wheat) 37 14 12 81 43 55 61 46 39 76 5 87 42 40 102 92 104 91 24 98
Cupcakes (chocolate, with low-fat frosting) 97 74 72 141 103 115 121 106 99 136 65 147 102 100 162 152 164 151 84 158
Danish (with fruit) 194 171 169 238 200 212 218 203 196 233 162 244 199 197 259 249 261 248 181 255
Donuts (yeast-leavened, glazed) 158 135 133 202 164 176 182 167 160 197 126 208 163 161 223 213 225 212 145 219
Fruit rolls 5 -18 -20 49 11 23 29 14 7 44 -27 55 10 8 70 60 72 59 -8 66
Graham crackers 25 2 0 69 31 43 49 34 27 64 -7 75 30 28 90 80 92 79 12 86
Granola bars (oats, fruit, and nut) 42 19 17 86 48 60 66 51 44 81 10 92 47 45 107 97 109 96 29 103
Ice cream (vanilla, light) 119 96 94 163 125 137 143 128 121 158 87 169 124 122 184 174 186 173 106 180
Muffins (blueberry) 292 269 267 336 298 310 316 301 294 331 260 342 297 295 357 347 359 346 279 353
Pizza, from frozen (cheese, regular crust) 175 152 150 219 181 193 199 184 177 214 143 225 180 178 240 230 242 229 162 236
Popsicles and bars (fruit/juice bars) 3 -20 -22 47 9 21 27 12 5 42 -29 53 8 6 68 58 70 57 -10 64
Potato chips (plain, salted) 92 69 67 136 98 110 116 101 94 131 60 142 97 95 157 147 159 146 79 153
Pretzels (hard, plain, salted) 91 68 66 135 97 109 115 100 93 130 59 141 96 94 156 146 158 145 78 152
Pudding, ready-to-eat (vanilla) 75 52 50 119 81 93 99 84 77 114 43 125 80 78 140 130 142 129 62 136
Sandwich crackers (rye with cheese filling) 106 83 81 150 112 124 130 115 108 145 74 156 111 109 171 161 173 160 93 167
Toaster pastries (fruit frosted) 222 199 197 266 228 240 246 231 224 261 190 272 227 225 287 277 289 276 209 283
Tortilla chips (white) 84 61 59 128 90 102 108 93 86 123 52 134 89 87 149 139 151 138 71 145

B. USDA Cost Data Cleanup:

## Clean up the unnecessary rows based on BALNK 1st column (Unhealthy Snacks)
snackCostDF <- snackCostDF %>% filter(X != "" & X.1 != "")

## Remove unnecessary columns
snackCostDF <- snackCostDF %>% select(-contains("X."), -contains("Total"))
names(snackCostDF)[1] <- "Comfort_Snack"

snackCostDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Apples Applesauce..jarred Bananas Cantaloupe Fruit.cocktail..canned Grapes Oranges Peaches..canned Pineapple..canned Plums Raisins Strawberries Tangerine Watermelon Broccoli Carrots Celery Red.peppers Sweet.potatoes..cooked Tomatoes..grape.or.cherry
Chocolate candy -0.12 0.02 0.06 -0.14 -0.07 -0.08 0.04 -0.07 -0.02 -0.01 0.05 -0.17 -0.27 -0.01 0.06 0.05 0.08 -0.36 -0.09 -0.31
Cookies -0.20 -0.06 -0.02 -0.22 -0.15 -0.16 -0.04 -0.15 -0.10 -0.09 -0.03 -0.25 -0.35 -0.09 -0.02 -0.03 0.00 -0.44 -0.17 -0.39
Corn chips -0.15 -0.01 0.03 -0.17 -0.10 -0.11 0.01 -0.10 -0.05 -0.04 0.02 -0.20 -0.30 -0.04 0.03 0.02 0.05 -0.39 -0.12 -0.34
Crackers -0.20 -0.06 -0.02 -0.22 -0.15 -0.16 -0.04 -0.15 -0.10 -0.09 -0.03 -0.25 -0.35 -0.09 -0.02 -0.03 0.00 -0.44 -0.17 -0.39
Cupcakes -0.02 0.12 0.16 -0.04 0.03 0.02 0.14 0.03 0.08 0.09 0.15 -0.07 -0.17 0.09 0.16 0.15 0.18 -0.26 0.01 -0.21
Danish 0.11 0.25 0.29 0.09 0.16 0.15 0.27 0.16 0.21 0.22 0.28 0.06 -0.04 0.22 0.29 0.28 0.31 -0.13 0.14 -0.08
Donuts 0.00 0.14 0.18 -0.02 0.05 0.04 0.16 0.05 0.10 0.11 0.17 -0.05 -0.15 0.11 0.18 0.17 0.20 -0.24 0.03 -0.19
Fruit rolls -0.08 0.06 0.10 -0.10 -0.03 -0.04 0.08 -0.03 0.02 0.03 0.09 -0.13 -0.23 0.03 0.10 0.09 0.12 -0.32 -0.05 -0.27
Graham crackers -0.22 -0.08 -0.04 -0.24 -0.17 -0.18 -0.06 -0.17 -0.12 -0.11 -0.05 -0.27 -0.37 -0.11 -0.04 -0.05 -0.02 -0.46 -0.19 -0.41
Granola bars -0.06 0.08 0.12 -0.08 -0.01 -0.02 0.10 -0.01 0.04 0.05 0.11 -0.11 -0.21 0.05 0.12 0.11 0.14 -0.30 -0.03 -0.25
Ice cream 0.03 0.17 0.21 0.01 0.08 0.07 0.19 0.08 0.13 0.14 0.20 -0.02 -0.12 0.14 0.21 0.20 0.23 -0.21 0.06 -0.16
Muffins 0.47 0.61 0.65 0.45 0.52 0.51 0.63 0.52 0.57 0.58 0.64 0.42 0.32 0.58 0.65 0.64 0.67 0.23 0.50 0.28
Pizza, from frozen 0.27 0.41 0.45 0.25 0.32 0.31 0.43 0.32 0.37 0.38 0.44 0.22 0.12 0.38 0.45 0.44 0.47 0.03 0.30 0.08
Popsicles and bars -0.02 0.12 0.16 -0.04 0.03 0.02 0.14 0.03 0.08 0.09 0.15 -0.07 -0.17 0.09 0.16 0.15 0.18 -0.26 0.01 -0.21
Potato chips -0.09 0.05 0.09 -0.11 -0.04 -0.05 0.07 -0.04 0.01 0.02 0.08 -0.14 -0.24 0.02 0.09 0.08 0.11 -0.33 -0.06 -0.28
Pretzels -0.11 0.03 0.07 -0.13 -0.06 -0.07 0.05 -0.06 -0.01 0.00 0.06 -0.16 -0.26 0.00 0.07 0.06 0.09 -0.35 -0.08 -0.30
Pudding, ready-to-eat 0.02 0.16 0.20 0.00 0.07 0.06 0.18 0.07 0.12 0.13 0.19 -0.03 -0.13 0.13 0.20 0.19 0.22 -0.22 0.05 -0.17
Sandwich crackers -0.16 -0.02 0.02 -0.18 -0.11 -0.12 0.00 -0.11 -0.06 -0.05 0.01 -0.21 -0.31 -0.05 0.02 0.01 0.04 -0.40 -0.13 -0.35
Toaster pastries -0.01 0.13 0.17 -0.03 0.04 0.03 0.15 0.04 0.09 0.10 0.16 -0.06 -0.16 0.10 0.17 0.16 0.19 -0.25 0.02 -0.20
Tortilla chips -0.15 -0.01 0.03 -0.17 -0.10 -0.11 0.01 -0.10 -0.05 -0.04 0.02 -0.20 -0.30 -0.04 0.03 0.02 0.05 -0.39 -0.12 -0.34
  1. Use tidyr function gather() to unpivot series of Healthy Snack alternative columns into a valriable called ‘Healthy_Snack_Alternative’ in both Calorie and Cost Impact data frames:

A. USDA snack Calorie Data Transformation:

snackCalorieDF <- snackCalorieDF %>% gather(key = 'Healthy_Snack_Alternative', value = "Calorie_Impact", -Comfort_Snack) 

snackCalorieDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Healthy_Snack_Alternative Calorie_Impact
Chocolate candy (milk chocolate candies) Apples 185
Cookies (chocolate chip, soft) Apples 46
Corn chips Apples 63
Crackers (wheat) Apples 37
Cupcakes (chocolate, with low-fat frosting) Apples 97
Danish (with fruit) Apples 194
Donuts (yeast-leavened, glazed) Apples 158
Fruit rolls Apples 5
Graham crackers Apples 25
Granola bars (oats, fruit, and nut) Apples 42
Ice cream (vanilla, light) Apples 119
Muffins (blueberry) Apples 292
Pizza, from frozen (cheese, regular crust) Apples 175
Popsicles and bars (fruit/juice bars) Apples 3
Potato chips (plain, salted) Apples 92
Pretzels (hard, plain, salted) Apples 91
Pudding, ready-to-eat (vanilla) Apples 75
Sandwich crackers (rye with cheese filling) Apples 106
Toaster pastries (fruit frosted) Apples 222
Tortilla chips (white) Apples 84
Chocolate candy (milk chocolate candies) Applesauce..sweetened. 162
Cookies (chocolate chip, soft) Applesauce..sweetened. 23
Corn chips Applesauce..sweetened. 40
Crackers (wheat) Applesauce..sweetened. 14
Cupcakes (chocolate, with low-fat frosting) Applesauce..sweetened. 74
Danish (with fruit) Applesauce..sweetened. 171
Donuts (yeast-leavened, glazed) Applesauce..sweetened. 135
Fruit rolls Applesauce..sweetened. -18
Graham crackers Applesauce..sweetened. 2
Granola bars (oats, fruit, and nut) Applesauce..sweetened. 19
Ice cream (vanilla, light) Applesauce..sweetened. 96
Muffins (blueberry) Applesauce..sweetened. 269
Pizza, from frozen (cheese, regular crust) Applesauce..sweetened. 152
Popsicles and bars (fruit/juice bars) Applesauce..sweetened. -20
Potato chips (plain, salted) Applesauce..sweetened. 69
Pretzels (hard, plain, salted) Applesauce..sweetened. 68
Pudding, ready-to-eat (vanilla) Applesauce..sweetened. 52
Sandwich crackers (rye with cheese filling) Applesauce..sweetened. 83
Toaster pastries (fruit frosted) Applesauce..sweetened. 199
Tortilla chips (white) Applesauce..sweetened. 61
Chocolate candy (milk chocolate candies) Bananas 160
Cookies (chocolate chip, soft) Bananas 21
Corn chips Bananas 38
Crackers (wheat) Bananas 12
Cupcakes (chocolate, with low-fat frosting) Bananas 72
Danish (with fruit) Bananas 169
Donuts (yeast-leavened, glazed) Bananas 133
Fruit rolls Bananas -20
Graham crackers Bananas 0
Granola bars (oats, fruit, and nut) Bananas 17
Ice cream (vanilla, light) Bananas 94
Muffins (blueberry) Bananas 267
Pizza, from frozen (cheese, regular crust) Bananas 150
Popsicles and bars (fruit/juice bars) Bananas -22
Potato chips (plain, salted) Bananas 67
Pretzels (hard, plain, salted) Bananas 66
Pudding, ready-to-eat (vanilla) Bananas 50
Sandwich crackers (rye with cheese filling) Bananas 81
Toaster pastries (fruit frosted) Bananas 197
Tortilla chips (white) Bananas 59
Chocolate candy (milk chocolate candies) Cantaloupe 229
Cookies (chocolate chip, soft) Cantaloupe 90
Corn chips Cantaloupe 107
Crackers (wheat) Cantaloupe 81
Cupcakes (chocolate, with low-fat frosting) Cantaloupe 141
Danish (with fruit) Cantaloupe 238
Donuts (yeast-leavened, glazed) Cantaloupe 202
Fruit rolls Cantaloupe 49
Graham crackers Cantaloupe 69
Granola bars (oats, fruit, and nut) Cantaloupe 86
Ice cream (vanilla, light) Cantaloupe 163
Muffins (blueberry) Cantaloupe 336
Pizza, from frozen (cheese, regular crust) Cantaloupe 219
Popsicles and bars (fruit/juice bars) Cantaloupe 47
Potato chips (plain, salted) Cantaloupe 136
Pretzels (hard, plain, salted) Cantaloupe 135
Pudding, ready-to-eat (vanilla) Cantaloupe 119
Sandwich crackers (rye with cheese filling) Cantaloupe 150
Toaster pastries (fruit frosted) Cantaloupe 266
Tortilla chips (white) Cantaloupe 128
Chocolate candy (milk chocolate candies) Fruit.cocktail..in.light.syrup. 191
Cookies (chocolate chip, soft) Fruit.cocktail..in.light.syrup. 52
Corn chips Fruit.cocktail..in.light.syrup. 69
Crackers (wheat) Fruit.cocktail..in.light.syrup. 43
Cupcakes (chocolate, with low-fat frosting) Fruit.cocktail..in.light.syrup. 103
Danish (with fruit) Fruit.cocktail..in.light.syrup. 200
Donuts (yeast-leavened, glazed) Fruit.cocktail..in.light.syrup. 164
Fruit rolls Fruit.cocktail..in.light.syrup. 11
Graham crackers Fruit.cocktail..in.light.syrup. 31
Granola bars (oats, fruit, and nut) Fruit.cocktail..in.light.syrup. 48
Ice cream (vanilla, light) Fruit.cocktail..in.light.syrup. 125
Muffins (blueberry) Fruit.cocktail..in.light.syrup. 298
Pizza, from frozen (cheese, regular crust) Fruit.cocktail..in.light.syrup. 181
Popsicles and bars (fruit/juice bars) Fruit.cocktail..in.light.syrup. 9
Potato chips (plain, salted) Fruit.cocktail..in.light.syrup. 98
Pretzels (hard, plain, salted) Fruit.cocktail..in.light.syrup. 97
Pudding, ready-to-eat (vanilla) Fruit.cocktail..in.light.syrup. 81
Sandwich crackers (rye with cheese filling) Fruit.cocktail..in.light.syrup. 112
Toaster pastries (fruit frosted) Fruit.cocktail..in.light.syrup. 228
Tortilla chips (white) Fruit.cocktail..in.light.syrup. 90
Chocolate candy (milk chocolate candies) Grapes 203
Cookies (chocolate chip, soft) Grapes 64
Corn chips Grapes 81
Crackers (wheat) Grapes 55
Cupcakes (chocolate, with low-fat frosting) Grapes 115
Danish (with fruit) Grapes 212
Donuts (yeast-leavened, glazed) Grapes 176
Fruit rolls Grapes 23
Graham crackers Grapes 43
Granola bars (oats, fruit, and nut) Grapes 60
Ice cream (vanilla, light) Grapes 137
Muffins (blueberry) Grapes 310
Pizza, from frozen (cheese, regular crust) Grapes 193
Popsicles and bars (fruit/juice bars) Grapes 21
Potato chips (plain, salted) Grapes 110
Pretzels (hard, plain, salted) Grapes 109
Pudding, ready-to-eat (vanilla) Grapes 93
Sandwich crackers (rye with cheese filling) Grapes 124
Toaster pastries (fruit frosted) Grapes 240
Tortilla chips (white) Grapes 102
Chocolate candy (milk chocolate candies) Oranges 209
Cookies (chocolate chip, soft) Oranges 70
Corn chips Oranges 87
Crackers (wheat) Oranges 61
Cupcakes (chocolate, with low-fat frosting) Oranges 121
Danish (with fruit) Oranges 218
Donuts (yeast-leavened, glazed) Oranges 182
Fruit rolls Oranges 29
Graham crackers Oranges 49
Granola bars (oats, fruit, and nut) Oranges 66
Ice cream (vanilla, light) Oranges 143
Muffins (blueberry) Oranges 316
Pizza, from frozen (cheese, regular crust) Oranges 199
Popsicles and bars (fruit/juice bars) Oranges 27
Potato chips (plain, salted) Oranges 116
Pretzels (hard, plain, salted) Oranges 115
Pudding, ready-to-eat (vanilla) Oranges 99
Sandwich crackers (rye with cheese filling) Oranges 130
Toaster pastries (fruit frosted) Oranges 246
Tortilla chips (white) Oranges 108
Chocolate candy (milk chocolate candies) Peaches..in.light.syrup. 194
Cookies (chocolate chip, soft) Peaches..in.light.syrup. 55
Corn chips Peaches..in.light.syrup. 72
Crackers (wheat) Peaches..in.light.syrup. 46
Cupcakes (chocolate, with low-fat frosting) Peaches..in.light.syrup. 106
Danish (with fruit) Peaches..in.light.syrup. 203
Donuts (yeast-leavened, glazed) Peaches..in.light.syrup. 167
Fruit rolls Peaches..in.light.syrup. 14
Graham crackers Peaches..in.light.syrup. 34
Granola bars (oats, fruit, and nut) Peaches..in.light.syrup. 51
Ice cream (vanilla, light) Peaches..in.light.syrup. 128
Muffins (blueberry) Peaches..in.light.syrup. 301
Pizza, from frozen (cheese, regular crust) Peaches..in.light.syrup. 184
Popsicles and bars (fruit/juice bars) Peaches..in.light.syrup. 12
Potato chips (plain, salted) Peaches..in.light.syrup. 101
Pretzels (hard, plain, salted) Peaches..in.light.syrup. 100
Pudding, ready-to-eat (vanilla) Peaches..in.light.syrup. 84
Sandwich crackers (rye with cheese filling) Peaches..in.light.syrup. 115
Toaster pastries (fruit frosted) Peaches..in.light.syrup. 231
Tortilla chips (white) Peaches..in.light.syrup. 93
Chocolate candy (milk chocolate candies) Pineapple..juice.pack. 187
Cookies (chocolate chip, soft) Pineapple..juice.pack. 48
Corn chips Pineapple..juice.pack. 65
Crackers (wheat) Pineapple..juice.pack. 39
Cupcakes (chocolate, with low-fat frosting) Pineapple..juice.pack. 99
Danish (with fruit) Pineapple..juice.pack. 196
Donuts (yeast-leavened, glazed) Pineapple..juice.pack. 160
Fruit rolls Pineapple..juice.pack. 7
Graham crackers Pineapple..juice.pack. 27
Granola bars (oats, fruit, and nut) Pineapple..juice.pack. 44
Ice cream (vanilla, light) Pineapple..juice.pack. 121
Muffins (blueberry) Pineapple..juice.pack. 294
Pizza, from frozen (cheese, regular crust) Pineapple..juice.pack. 177
Popsicles and bars (fruit/juice bars) Pineapple..juice.pack. 5
Potato chips (plain, salted) Pineapple..juice.pack. 94
Pretzels (hard, plain, salted) Pineapple..juice.pack. 93
Pudding, ready-to-eat (vanilla) Pineapple..juice.pack. 77
Sandwich crackers (rye with cheese filling) Pineapple..juice.pack. 108
Toaster pastries (fruit frosted) Pineapple..juice.pack. 224
Tortilla chips (white) Pineapple..juice.pack. 86
Chocolate candy (milk chocolate candies) Plums 224
Cookies (chocolate chip, soft) Plums 85
Corn chips Plums 102
Crackers (wheat) Plums 76
Cupcakes (chocolate, with low-fat frosting) Plums 136
Danish (with fruit) Plums 233
Donuts (yeast-leavened, glazed) Plums 197
Fruit rolls Plums 44
Graham crackers Plums 64
Granola bars (oats, fruit, and nut) Plums 81
Ice cream (vanilla, light) Plums 158
Muffins (blueberry) Plums 331
Pizza, from frozen (cheese, regular crust) Plums 214
Popsicles and bars (fruit/juice bars) Plums 42
Potato chips (plain, salted) Plums 131
Pretzels (hard, plain, salted) Plums 130
Pudding, ready-to-eat (vanilla) Plums 114
Sandwich crackers (rye with cheese filling) Plums 145
Toaster pastries (fruit frosted) Plums 261
Tortilla chips (white) Plums 123
Chocolate candy (milk chocolate candies) Raisins 153
Cookies (chocolate chip, soft) Raisins 14
Corn chips Raisins 31
Crackers (wheat) Raisins 5
Cupcakes (chocolate, with low-fat frosting) Raisins 65
Danish (with fruit) Raisins 162
Donuts (yeast-leavened, glazed) Raisins 126
Fruit rolls Raisins -27
Graham crackers Raisins -7
Granola bars (oats, fruit, and nut) Raisins 10
Ice cream (vanilla, light) Raisins 87
Muffins (blueberry) Raisins 260
Pizza, from frozen (cheese, regular crust) Raisins 143
Popsicles and bars (fruit/juice bars) Raisins -29
Potato chips (plain, salted) Raisins 60
Pretzels (hard, plain, salted) Raisins 59
Pudding, ready-to-eat (vanilla) Raisins 43
Sandwich crackers (rye with cheese filling) Raisins 74
Toaster pastries (fruit frosted) Raisins 190
Tortilla chips (white) Raisins 52
Chocolate candy (milk chocolate candies) Strawberries 235
Cookies (chocolate chip, soft) Strawberries 96
Corn chips Strawberries 113
Crackers (wheat) Strawberries 87
Cupcakes (chocolate, with low-fat frosting) Strawberries 147
Danish (with fruit) Strawberries 244
Donuts (yeast-leavened, glazed) Strawberries 208
Fruit rolls Strawberries 55
Graham crackers Strawberries 75
Granola bars (oats, fruit, and nut) Strawberries 92
Ice cream (vanilla, light) Strawberries 169
Muffins (blueberry) Strawberries 342
Pizza, from frozen (cheese, regular crust) Strawberries 225
Popsicles and bars (fruit/juice bars) Strawberries 53
Potato chips (plain, salted) Strawberries 142
Pretzels (hard, plain, salted) Strawberries 141
Pudding, ready-to-eat (vanilla) Strawberries 125
Sandwich crackers (rye with cheese filling) Strawberries 156
Toaster pastries (fruit frosted) Strawberries 272
Tortilla chips (white) Strawberries 134
Chocolate candy (milk chocolate candies) Tangerine 190
Cookies (chocolate chip, soft) Tangerine 51
Corn chips Tangerine 68
Crackers (wheat) Tangerine 42
Cupcakes (chocolate, with low-fat frosting) Tangerine 102
Danish (with fruit) Tangerine 199
Donuts (yeast-leavened, glazed) Tangerine 163
Fruit rolls Tangerine 10
Graham crackers Tangerine 30
Granola bars (oats, fruit, and nut) Tangerine 47
Ice cream (vanilla, light) Tangerine 124
Muffins (blueberry) Tangerine 297
Pizza, from frozen (cheese, regular crust) Tangerine 180
Popsicles and bars (fruit/juice bars) Tangerine 8
Potato chips (plain, salted) Tangerine 97
Pretzels (hard, plain, salted) Tangerine 96
Pudding, ready-to-eat (vanilla) Tangerine 80
Sandwich crackers (rye with cheese filling) Tangerine 111
Toaster pastries (fruit frosted) Tangerine 227
Tortilla chips (white) Tangerine 89
Chocolate candy (milk chocolate candies) Watermelon 188
Cookies (chocolate chip, soft) Watermelon 49
Corn chips Watermelon 66
Crackers (wheat) Watermelon 40
Cupcakes (chocolate, with low-fat frosting) Watermelon 100
Danish (with fruit) Watermelon 197
Donuts (yeast-leavened, glazed) Watermelon 161
Fruit rolls Watermelon 8
Graham crackers Watermelon 28
Granola bars (oats, fruit, and nut) Watermelon 45
Ice cream (vanilla, light) Watermelon 122
Muffins (blueberry) Watermelon 295
Pizza, from frozen (cheese, regular crust) Watermelon 178
Popsicles and bars (fruit/juice bars) Watermelon 6
Potato chips (plain, salted) Watermelon 95
Pretzels (hard, plain, salted) Watermelon 94
Pudding, ready-to-eat (vanilla) Watermelon 78
Sandwich crackers (rye with cheese filling) Watermelon 109
Toaster pastries (fruit frosted) Watermelon 225
Tortilla chips (white) Watermelon 87
Chocolate candy (milk chocolate candies) Broccoli 250
Cookies (chocolate chip, soft) Broccoli 111
Corn chips Broccoli 128
Crackers (wheat) Broccoli 102
Cupcakes (chocolate, with low-fat frosting) Broccoli 162
Danish (with fruit) Broccoli 259
Donuts (yeast-leavened, glazed) Broccoli 223
Fruit rolls Broccoli 70
Graham crackers Broccoli 90
Granola bars (oats, fruit, and nut) Broccoli 107
Ice cream (vanilla, light) Broccoli 184
Muffins (blueberry) Broccoli 357
Pizza, from frozen (cheese, regular crust) Broccoli 240
Popsicles and bars (fruit/juice bars) Broccoli 68
Potato chips (plain, salted) Broccoli 157
Pretzels (hard, plain, salted) Broccoli 156
Pudding, ready-to-eat (vanilla) Broccoli 140
Sandwich crackers (rye with cheese filling) Broccoli 171
Toaster pastries (fruit frosted) Broccoli 287
Tortilla chips (white) Broccoli 149
Chocolate candy (milk chocolate candies) Carrots 240
Cookies (chocolate chip, soft) Carrots 101
Corn chips Carrots 118
Crackers (wheat) Carrots 92
Cupcakes (chocolate, with low-fat frosting) Carrots 152
Danish (with fruit) Carrots 249
Donuts (yeast-leavened, glazed) Carrots 213
Fruit rolls Carrots 60
Graham crackers Carrots 80
Granola bars (oats, fruit, and nut) Carrots 97
Ice cream (vanilla, light) Carrots 174
Muffins (blueberry) Carrots 347
Pizza, from frozen (cheese, regular crust) Carrots 230
Popsicles and bars (fruit/juice bars) Carrots 58
Potato chips (plain, salted) Carrots 147
Pretzels (hard, plain, salted) Carrots 146
Pudding, ready-to-eat (vanilla) Carrots 130
Sandwich crackers (rye with cheese filling) Carrots 161
Toaster pastries (fruit frosted) Carrots 277
Tortilla chips (white) Carrots 139
Chocolate candy (milk chocolate candies) Celery 252
Cookies (chocolate chip, soft) Celery 113
Corn chips Celery 130
Crackers (wheat) Celery 104
Cupcakes (chocolate, with low-fat frosting) Celery 164
Danish (with fruit) Celery 261
Donuts (yeast-leavened, glazed) Celery 225
Fruit rolls Celery 72
Graham crackers Celery 92
Granola bars (oats, fruit, and nut) Celery 109
Ice cream (vanilla, light) Celery 186
Muffins (blueberry) Celery 359
Pizza, from frozen (cheese, regular crust) Celery 242
Popsicles and bars (fruit/juice bars) Celery 70
Potato chips (plain, salted) Celery 159
Pretzels (hard, plain, salted) Celery 158
Pudding, ready-to-eat (vanilla) Celery 142
Sandwich crackers (rye with cheese filling) Celery 173
Toaster pastries (fruit frosted) Celery 289
Tortilla chips (white) Celery 151
Chocolate candy (milk chocolate candies) Red.Peppers 239
Cookies (chocolate chip, soft) Red.Peppers 100
Corn chips Red.Peppers 117
Crackers (wheat) Red.Peppers 91
Cupcakes (chocolate, with low-fat frosting) Red.Peppers 151
Danish (with fruit) Red.Peppers 248
Donuts (yeast-leavened, glazed) Red.Peppers 212
Fruit rolls Red.Peppers 59
Graham crackers Red.Peppers 79
Granola bars (oats, fruit, and nut) Red.Peppers 96
Ice cream (vanilla, light) Red.Peppers 173
Muffins (blueberry) Red.Peppers 346
Pizza, from frozen (cheese, regular crust) Red.Peppers 229
Popsicles and bars (fruit/juice bars) Red.Peppers 57
Potato chips (plain, salted) Red.Peppers 146
Pretzels (hard, plain, salted) Red.Peppers 145
Pudding, ready-to-eat (vanilla) Red.Peppers 129
Sandwich crackers (rye with cheese filling) Red.Peppers 160
Toaster pastries (fruit frosted) Red.Peppers 276
Tortilla chips (white) Red.Peppers 138
Chocolate candy (milk chocolate candies) Sweet.potatoes 172
Cookies (chocolate chip, soft) Sweet.potatoes 33
Corn chips Sweet.potatoes 50
Crackers (wheat) Sweet.potatoes 24
Cupcakes (chocolate, with low-fat frosting) Sweet.potatoes 84
Danish (with fruit) Sweet.potatoes 181
Donuts (yeast-leavened, glazed) Sweet.potatoes 145
Fruit rolls Sweet.potatoes -8
Graham crackers Sweet.potatoes 12
Granola bars (oats, fruit, and nut) Sweet.potatoes 29
Ice cream (vanilla, light) Sweet.potatoes 106
Muffins (blueberry) Sweet.potatoes 279
Pizza, from frozen (cheese, regular crust) Sweet.potatoes 162
Popsicles and bars (fruit/juice bars) Sweet.potatoes -10
Potato chips (plain, salted) Sweet.potatoes 79
Pretzels (hard, plain, salted) Sweet.potatoes 78
Pudding, ready-to-eat (vanilla) Sweet.potatoes 62
Sandwich crackers (rye with cheese filling) Sweet.potatoes 93
Toaster pastries (fruit frosted) Sweet.potatoes 209
Tortilla chips (white) Sweet.potatoes 71
Chocolate candy (milk chocolate candies) Tomatoes 246
Cookies (chocolate chip, soft) Tomatoes 107
Corn chips Tomatoes 124
Crackers (wheat) Tomatoes 98
Cupcakes (chocolate, with low-fat frosting) Tomatoes 158
Danish (with fruit) Tomatoes 255
Donuts (yeast-leavened, glazed) Tomatoes 219
Fruit rolls Tomatoes 66
Graham crackers Tomatoes 86
Granola bars (oats, fruit, and nut) Tomatoes 103
Ice cream (vanilla, light) Tomatoes 180
Muffins (blueberry) Tomatoes 353
Pizza, from frozen (cheese, regular crust) Tomatoes 236
Popsicles and bars (fruit/juice bars) Tomatoes 64
Potato chips (plain, salted) Tomatoes 153
Pretzels (hard, plain, salted) Tomatoes 152
Pudding, ready-to-eat (vanilla) Tomatoes 136
Sandwich crackers (rye with cheese filling) Tomatoes 167
Toaster pastries (fruit frosted) Tomatoes 283
Tortilla chips (white) Tomatoes 145

Both the Snack columns need further cleanup and standardization so that two data frames can eventually be combined into one data frame for further analysis. As part of the cleanup of ‘Comfort_Snack’ variable, only the section of the name before the beginning of parenthesis (‘(’)is kept. For ‘Healthy_Snack_Alternative’ variable, section of the name appearing before (‘..’) characters is kept with any dot (‘.’) character in the resultant string replaced with a space character.

### Clean up 'Comfort_Snack' column
snackCalorieDF$Comfort_Snack <-
  str_trim(
    ifelse(is.na(str_locate(snackCalorieDF$Comfort_Snack,"\\(")[,"start"]), snackCalorieDF$Comfort_Snack,str_sub(snackCalorieDF$Comfort_Snack, 1, str_locate(snackCalorieDF$Comfort_Snack,"\\(")[,"start"] - 1)
  )
)

### Cleanup 'Healthy_Snack_Alternative' column    
snackCalorieDF$Healthy_Snack_Alternative <-
  str_trim(
    str_replace(
      ifelse(is.na(str_locate(snackCalorieDF$Healthy_Snack_Alternative,"\\.\\.")[,"start"]),
             snackCalorieDF$Healthy_Snack_Alternative,{str_sub(snackCalorieDF$Healthy_Snack_Alternative, 1, str_locate(snackCalorieDF$Healthy_Snack_Alternative,"\\.\\.")[,"start"] - 1)}),"\\."," ")
    )

snackCalorieDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Healthy_Snack_Alternative Calorie_Impact
Chocolate candy Apples 185
Cookies Apples 46
Corn chips Apples 63
Crackers Apples 37
Cupcakes Apples 97
Danish Apples 194
Donuts Apples 158
Fruit rolls Apples 5
Graham crackers Apples 25
Granola bars Apples 42
Ice cream Apples 119
Muffins Apples 292
Pizza, from frozen Apples 175
Popsicles and bars Apples 3
Potato chips Apples 92
Pretzels Apples 91
Pudding, ready-to-eat Apples 75
Sandwich crackers Apples 106
Toaster pastries Apples 222
Tortilla chips Apples 84
Chocolate candy Applesauce 162
Cookies Applesauce 23
Corn chips Applesauce 40
Crackers Applesauce 14
Cupcakes Applesauce 74
Danish Applesauce 171
Donuts Applesauce 135
Fruit rolls Applesauce -18
Graham crackers Applesauce 2
Granola bars Applesauce 19
Ice cream Applesauce 96
Muffins Applesauce 269
Pizza, from frozen Applesauce 152
Popsicles and bars Applesauce -20
Potato chips Applesauce 69
Pretzels Applesauce 68
Pudding, ready-to-eat Applesauce 52
Sandwich crackers Applesauce 83
Toaster pastries Applesauce 199
Tortilla chips Applesauce 61
Chocolate candy Bananas 160
Cookies Bananas 21
Corn chips Bananas 38
Crackers Bananas 12
Cupcakes Bananas 72
Danish Bananas 169
Donuts Bananas 133
Fruit rolls Bananas -20
Graham crackers Bananas 0
Granola bars Bananas 17
Ice cream Bananas 94
Muffins Bananas 267
Pizza, from frozen Bananas 150
Popsicles and bars Bananas -22
Potato chips Bananas 67
Pretzels Bananas 66
Pudding, ready-to-eat Bananas 50
Sandwich crackers Bananas 81
Toaster pastries Bananas 197
Tortilla chips Bananas 59
Chocolate candy Cantaloupe 229
Cookies Cantaloupe 90
Corn chips Cantaloupe 107
Crackers Cantaloupe 81
Cupcakes Cantaloupe 141
Danish Cantaloupe 238
Donuts Cantaloupe 202
Fruit rolls Cantaloupe 49
Graham crackers Cantaloupe 69
Granola bars Cantaloupe 86
Ice cream Cantaloupe 163
Muffins Cantaloupe 336
Pizza, from frozen Cantaloupe 219
Popsicles and bars Cantaloupe 47
Potato chips Cantaloupe 136
Pretzels Cantaloupe 135
Pudding, ready-to-eat Cantaloupe 119
Sandwich crackers Cantaloupe 150
Toaster pastries Cantaloupe 266
Tortilla chips Cantaloupe 128
Chocolate candy Fruit cocktail 191
Cookies Fruit cocktail 52
Corn chips Fruit cocktail 69
Crackers Fruit cocktail 43
Cupcakes Fruit cocktail 103
Danish Fruit cocktail 200
Donuts Fruit cocktail 164
Fruit rolls Fruit cocktail 11
Graham crackers Fruit cocktail 31
Granola bars Fruit cocktail 48
Ice cream Fruit cocktail 125
Muffins Fruit cocktail 298
Pizza, from frozen Fruit cocktail 181
Popsicles and bars Fruit cocktail 9
Potato chips Fruit cocktail 98
Pretzels Fruit cocktail 97
Pudding, ready-to-eat Fruit cocktail 81
Sandwich crackers Fruit cocktail 112
Toaster pastries Fruit cocktail 228
Tortilla chips Fruit cocktail 90
Chocolate candy Grapes 203
Cookies Grapes 64
Corn chips Grapes 81
Crackers Grapes 55
Cupcakes Grapes 115
Danish Grapes 212
Donuts Grapes 176
Fruit rolls Grapes 23
Graham crackers Grapes 43
Granola bars Grapes 60
Ice cream Grapes 137
Muffins Grapes 310
Pizza, from frozen Grapes 193
Popsicles and bars Grapes 21
Potato chips Grapes 110
Pretzels Grapes 109
Pudding, ready-to-eat Grapes 93
Sandwich crackers Grapes 124
Toaster pastries Grapes 240
Tortilla chips Grapes 102
Chocolate candy Oranges 209
Cookies Oranges 70
Corn chips Oranges 87
Crackers Oranges 61
Cupcakes Oranges 121
Danish Oranges 218
Donuts Oranges 182
Fruit rolls Oranges 29
Graham crackers Oranges 49
Granola bars Oranges 66
Ice cream Oranges 143
Muffins Oranges 316
Pizza, from frozen Oranges 199
Popsicles and bars Oranges 27
Potato chips Oranges 116
Pretzels Oranges 115
Pudding, ready-to-eat Oranges 99
Sandwich crackers Oranges 130
Toaster pastries Oranges 246
Tortilla chips Oranges 108
Chocolate candy Peaches 194
Cookies Peaches 55
Corn chips Peaches 72
Crackers Peaches 46
Cupcakes Peaches 106
Danish Peaches 203
Donuts Peaches 167
Fruit rolls Peaches 14
Graham crackers Peaches 34
Granola bars Peaches 51
Ice cream Peaches 128
Muffins Peaches 301
Pizza, from frozen Peaches 184
Popsicles and bars Peaches 12
Potato chips Peaches 101
Pretzels Peaches 100
Pudding, ready-to-eat Peaches 84
Sandwich crackers Peaches 115
Toaster pastries Peaches 231
Tortilla chips Peaches 93
Chocolate candy Pineapple 187
Cookies Pineapple 48
Corn chips Pineapple 65
Crackers Pineapple 39
Cupcakes Pineapple 99
Danish Pineapple 196
Donuts Pineapple 160
Fruit rolls Pineapple 7
Graham crackers Pineapple 27
Granola bars Pineapple 44
Ice cream Pineapple 121
Muffins Pineapple 294
Pizza, from frozen Pineapple 177
Popsicles and bars Pineapple 5
Potato chips Pineapple 94
Pretzels Pineapple 93
Pudding, ready-to-eat Pineapple 77
Sandwich crackers Pineapple 108
Toaster pastries Pineapple 224
Tortilla chips Pineapple 86
Chocolate candy Plums 224
Cookies Plums 85
Corn chips Plums 102
Crackers Plums 76
Cupcakes Plums 136
Danish Plums 233
Donuts Plums 197
Fruit rolls Plums 44
Graham crackers Plums 64
Granola bars Plums 81
Ice cream Plums 158
Muffins Plums 331
Pizza, from frozen Plums 214
Popsicles and bars Plums 42
Potato chips Plums 131
Pretzels Plums 130
Pudding, ready-to-eat Plums 114
Sandwich crackers Plums 145
Toaster pastries Plums 261
Tortilla chips Plums 123
Chocolate candy Raisins 153
Cookies Raisins 14
Corn chips Raisins 31
Crackers Raisins 5
Cupcakes Raisins 65
Danish Raisins 162
Donuts Raisins 126
Fruit rolls Raisins -27
Graham crackers Raisins -7
Granola bars Raisins 10
Ice cream Raisins 87
Muffins Raisins 260
Pizza, from frozen Raisins 143
Popsicles and bars Raisins -29
Potato chips Raisins 60
Pretzels Raisins 59
Pudding, ready-to-eat Raisins 43
Sandwich crackers Raisins 74
Toaster pastries Raisins 190
Tortilla chips Raisins 52
Chocolate candy Strawberries 235
Cookies Strawberries 96
Corn chips Strawberries 113
Crackers Strawberries 87
Cupcakes Strawberries 147
Danish Strawberries 244
Donuts Strawberries 208
Fruit rolls Strawberries 55
Graham crackers Strawberries 75
Granola bars Strawberries 92
Ice cream Strawberries 169
Muffins Strawberries 342
Pizza, from frozen Strawberries 225
Popsicles and bars Strawberries 53
Potato chips Strawberries 142
Pretzels Strawberries 141
Pudding, ready-to-eat Strawberries 125
Sandwich crackers Strawberries 156
Toaster pastries Strawberries 272
Tortilla chips Strawberries 134
Chocolate candy Tangerine 190
Cookies Tangerine 51
Corn chips Tangerine 68
Crackers Tangerine 42
Cupcakes Tangerine 102
Danish Tangerine 199
Donuts Tangerine 163
Fruit rolls Tangerine 10
Graham crackers Tangerine 30
Granola bars Tangerine 47
Ice cream Tangerine 124
Muffins Tangerine 297
Pizza, from frozen Tangerine 180
Popsicles and bars Tangerine 8
Potato chips Tangerine 97
Pretzels Tangerine 96
Pudding, ready-to-eat Tangerine 80
Sandwich crackers Tangerine 111
Toaster pastries Tangerine 227
Tortilla chips Tangerine 89
Chocolate candy Watermelon 188
Cookies Watermelon 49
Corn chips Watermelon 66
Crackers Watermelon 40
Cupcakes Watermelon 100
Danish Watermelon 197
Donuts Watermelon 161
Fruit rolls Watermelon 8
Graham crackers Watermelon 28
Granola bars Watermelon 45
Ice cream Watermelon 122
Muffins Watermelon 295
Pizza, from frozen Watermelon 178
Popsicles and bars Watermelon 6
Potato chips Watermelon 95
Pretzels Watermelon 94
Pudding, ready-to-eat Watermelon 78
Sandwich crackers Watermelon 109
Toaster pastries Watermelon 225
Tortilla chips Watermelon 87
Chocolate candy Broccoli 250
Cookies Broccoli 111
Corn chips Broccoli 128
Crackers Broccoli 102
Cupcakes Broccoli 162
Danish Broccoli 259
Donuts Broccoli 223
Fruit rolls Broccoli 70
Graham crackers Broccoli 90
Granola bars Broccoli 107
Ice cream Broccoli 184
Muffins Broccoli 357
Pizza, from frozen Broccoli 240
Popsicles and bars Broccoli 68
Potato chips Broccoli 157
Pretzels Broccoli 156
Pudding, ready-to-eat Broccoli 140
Sandwich crackers Broccoli 171
Toaster pastries Broccoli 287
Tortilla chips Broccoli 149
Chocolate candy Carrots 240
Cookies Carrots 101
Corn chips Carrots 118
Crackers Carrots 92
Cupcakes Carrots 152
Danish Carrots 249
Donuts Carrots 213
Fruit rolls Carrots 60
Graham crackers Carrots 80
Granola bars Carrots 97
Ice cream Carrots 174
Muffins Carrots 347
Pizza, from frozen Carrots 230
Popsicles and bars Carrots 58
Potato chips Carrots 147
Pretzels Carrots 146
Pudding, ready-to-eat Carrots 130
Sandwich crackers Carrots 161
Toaster pastries Carrots 277
Tortilla chips Carrots 139
Chocolate candy Celery 252
Cookies Celery 113
Corn chips Celery 130
Crackers Celery 104
Cupcakes Celery 164
Danish Celery 261
Donuts Celery 225
Fruit rolls Celery 72
Graham crackers Celery 92
Granola bars Celery 109
Ice cream Celery 186
Muffins Celery 359
Pizza, from frozen Celery 242
Popsicles and bars Celery 70
Potato chips Celery 159
Pretzels Celery 158
Pudding, ready-to-eat Celery 142
Sandwich crackers Celery 173
Toaster pastries Celery 289
Tortilla chips Celery 151
Chocolate candy Red Peppers 239
Cookies Red Peppers 100
Corn chips Red Peppers 117
Crackers Red Peppers 91
Cupcakes Red Peppers 151
Danish Red Peppers 248
Donuts Red Peppers 212
Fruit rolls Red Peppers 59
Graham crackers Red Peppers 79
Granola bars Red Peppers 96
Ice cream Red Peppers 173
Muffins Red Peppers 346
Pizza, from frozen Red Peppers 229
Popsicles and bars Red Peppers 57
Potato chips Red Peppers 146
Pretzels Red Peppers 145
Pudding, ready-to-eat Red Peppers 129
Sandwich crackers Red Peppers 160
Toaster pastries Red Peppers 276
Tortilla chips Red Peppers 138
Chocolate candy Sweet potatoes 172
Cookies Sweet potatoes 33
Corn chips Sweet potatoes 50
Crackers Sweet potatoes 24
Cupcakes Sweet potatoes 84
Danish Sweet potatoes 181
Donuts Sweet potatoes 145
Fruit rolls Sweet potatoes -8
Graham crackers Sweet potatoes 12
Granola bars Sweet potatoes 29
Ice cream Sweet potatoes 106
Muffins Sweet potatoes 279
Pizza, from frozen Sweet potatoes 162
Popsicles and bars Sweet potatoes -10
Potato chips Sweet potatoes 79
Pretzels Sweet potatoes 78
Pudding, ready-to-eat Sweet potatoes 62
Sandwich crackers Sweet potatoes 93
Toaster pastries Sweet potatoes 209
Tortilla chips Sweet potatoes 71
Chocolate candy Tomatoes 246
Cookies Tomatoes 107
Corn chips Tomatoes 124
Crackers Tomatoes 98
Cupcakes Tomatoes 158
Danish Tomatoes 255
Donuts Tomatoes 219
Fruit rolls Tomatoes 66
Graham crackers Tomatoes 86
Granola bars Tomatoes 103
Ice cream Tomatoes 180
Muffins Tomatoes 353
Pizza, from frozen Tomatoes 236
Popsicles and bars Tomatoes 64
Potato chips Tomatoes 153
Pretzels Tomatoes 152
Pudding, ready-to-eat Tomatoes 136
Sandwich crackers Tomatoes 167
Toaster pastries Tomatoes 283
Tortilla chips Tomatoes 145

B. USDA snack Cost Data Transformation:

Apply tidyr gather() to unpivot columns into a variable called ‘Healthy_Snack_Alternative’ -

snackCostDF <- snackCostDF %>% gather(key = 'Healthy_Snack_Alternative', value = "Cost_Impact", -Comfort_Snack) 

snackCostDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Healthy_Snack_Alternative Cost_Impact
Chocolate candy Apples -0.12
Cookies Apples -0.20
Corn chips Apples -0.15
Crackers Apples -0.20
Cupcakes Apples -0.02
Danish Apples 0.11
Donuts Apples 0.00
Fruit rolls Apples -0.08
Graham crackers Apples -0.22
Granola bars Apples -0.06
Ice cream Apples 0.03
Muffins Apples 0.47
Pizza, from frozen Apples 0.27
Popsicles and bars Apples -0.02
Potato chips Apples -0.09
Pretzels Apples -0.11
Pudding, ready-to-eat Apples 0.02
Sandwich crackers Apples -0.16
Toaster pastries Apples -0.01
Tortilla chips Apples -0.15
Chocolate candy Applesauce..jarred 0.02
Cookies Applesauce..jarred -0.06
Corn chips Applesauce..jarred -0.01
Crackers Applesauce..jarred -0.06
Cupcakes Applesauce..jarred 0.12
Danish Applesauce..jarred 0.25
Donuts Applesauce..jarred 0.14
Fruit rolls Applesauce..jarred 0.06
Graham crackers Applesauce..jarred -0.08
Granola bars Applesauce..jarred 0.08
Ice cream Applesauce..jarred 0.17
Muffins Applesauce..jarred 0.61
Pizza, from frozen Applesauce..jarred 0.41
Popsicles and bars Applesauce..jarred 0.12
Potato chips Applesauce..jarred 0.05
Pretzels Applesauce..jarred 0.03
Pudding, ready-to-eat Applesauce..jarred 0.16
Sandwich crackers Applesauce..jarred -0.02
Toaster pastries Applesauce..jarred 0.13
Tortilla chips Applesauce..jarred -0.01
Chocolate candy Bananas 0.06
Cookies Bananas -0.02
Corn chips Bananas 0.03
Crackers Bananas -0.02
Cupcakes Bananas 0.16
Danish Bananas 0.29
Donuts Bananas 0.18
Fruit rolls Bananas 0.10
Graham crackers Bananas -0.04
Granola bars Bananas 0.12
Ice cream Bananas 0.21
Muffins Bananas 0.65
Pizza, from frozen Bananas 0.45
Popsicles and bars Bananas 0.16
Potato chips Bananas 0.09
Pretzels Bananas 0.07
Pudding, ready-to-eat Bananas 0.20
Sandwich crackers Bananas 0.02
Toaster pastries Bananas 0.17
Tortilla chips Bananas 0.03
Chocolate candy Cantaloupe -0.14
Cookies Cantaloupe -0.22
Corn chips Cantaloupe -0.17
Crackers Cantaloupe -0.22
Cupcakes Cantaloupe -0.04
Danish Cantaloupe 0.09
Donuts Cantaloupe -0.02
Fruit rolls Cantaloupe -0.10
Graham crackers Cantaloupe -0.24
Granola bars Cantaloupe -0.08
Ice cream Cantaloupe 0.01
Muffins Cantaloupe 0.45
Pizza, from frozen Cantaloupe 0.25
Popsicles and bars Cantaloupe -0.04
Potato chips Cantaloupe -0.11
Pretzels Cantaloupe -0.13
Pudding, ready-to-eat Cantaloupe 0.00
Sandwich crackers Cantaloupe -0.18
Toaster pastries Cantaloupe -0.03
Tortilla chips Cantaloupe -0.17
Chocolate candy Fruit.cocktail..canned -0.07
Cookies Fruit.cocktail..canned -0.15
Corn chips Fruit.cocktail..canned -0.10
Crackers Fruit.cocktail..canned -0.15
Cupcakes Fruit.cocktail..canned 0.03
Danish Fruit.cocktail..canned 0.16
Donuts Fruit.cocktail..canned 0.05
Fruit rolls Fruit.cocktail..canned -0.03
Graham crackers Fruit.cocktail..canned -0.17
Granola bars Fruit.cocktail..canned -0.01
Ice cream Fruit.cocktail..canned 0.08
Muffins Fruit.cocktail..canned 0.52
Pizza, from frozen Fruit.cocktail..canned 0.32
Popsicles and bars Fruit.cocktail..canned 0.03
Potato chips Fruit.cocktail..canned -0.04
Pretzels Fruit.cocktail..canned -0.06
Pudding, ready-to-eat Fruit.cocktail..canned 0.07
Sandwich crackers Fruit.cocktail..canned -0.11
Toaster pastries Fruit.cocktail..canned 0.04
Tortilla chips Fruit.cocktail..canned -0.10
Chocolate candy Grapes -0.08
Cookies Grapes -0.16
Corn chips Grapes -0.11
Crackers Grapes -0.16
Cupcakes Grapes 0.02
Danish Grapes 0.15
Donuts Grapes 0.04
Fruit rolls Grapes -0.04
Graham crackers Grapes -0.18
Granola bars Grapes -0.02
Ice cream Grapes 0.07
Muffins Grapes 0.51
Pizza, from frozen Grapes 0.31
Popsicles and bars Grapes 0.02
Potato chips Grapes -0.05
Pretzels Grapes -0.07
Pudding, ready-to-eat Grapes 0.06
Sandwich crackers Grapes -0.12
Toaster pastries Grapes 0.03
Tortilla chips Grapes -0.11
Chocolate candy Oranges 0.04
Cookies Oranges -0.04
Corn chips Oranges 0.01
Crackers Oranges -0.04
Cupcakes Oranges 0.14
Danish Oranges 0.27
Donuts Oranges 0.16
Fruit rolls Oranges 0.08
Graham crackers Oranges -0.06
Granola bars Oranges 0.10
Ice cream Oranges 0.19
Muffins Oranges 0.63
Pizza, from frozen Oranges 0.43
Popsicles and bars Oranges 0.14
Potato chips Oranges 0.07
Pretzels Oranges 0.05
Pudding, ready-to-eat Oranges 0.18
Sandwich crackers Oranges 0.00
Toaster pastries Oranges 0.15
Tortilla chips Oranges 0.01
Chocolate candy Peaches..canned -0.07
Cookies Peaches..canned -0.15
Corn chips Peaches..canned -0.10
Crackers Peaches..canned -0.15
Cupcakes Peaches..canned 0.03
Danish Peaches..canned 0.16
Donuts Peaches..canned 0.05
Fruit rolls Peaches..canned -0.03
Graham crackers Peaches..canned -0.17
Granola bars Peaches..canned -0.01
Ice cream Peaches..canned 0.08
Muffins Peaches..canned 0.52
Pizza, from frozen Peaches..canned 0.32
Popsicles and bars Peaches..canned 0.03
Potato chips Peaches..canned -0.04
Pretzels Peaches..canned -0.06
Pudding, ready-to-eat Peaches..canned 0.07
Sandwich crackers Peaches..canned -0.11
Toaster pastries Peaches..canned 0.04
Tortilla chips Peaches..canned -0.10
Chocolate candy Pineapple..canned -0.02
Cookies Pineapple..canned -0.10
Corn chips Pineapple..canned -0.05
Crackers Pineapple..canned -0.10
Cupcakes Pineapple..canned 0.08
Danish Pineapple..canned 0.21
Donuts Pineapple..canned 0.10
Fruit rolls Pineapple..canned 0.02
Graham crackers Pineapple..canned -0.12
Granola bars Pineapple..canned 0.04
Ice cream Pineapple..canned 0.13
Muffins Pineapple..canned 0.57
Pizza, from frozen Pineapple..canned 0.37
Popsicles and bars Pineapple..canned 0.08
Potato chips Pineapple..canned 0.01
Pretzels Pineapple..canned -0.01
Pudding, ready-to-eat Pineapple..canned 0.12
Sandwich crackers Pineapple..canned -0.06
Toaster pastries Pineapple..canned 0.09
Tortilla chips Pineapple..canned -0.05
Chocolate candy Plums -0.01
Cookies Plums -0.09
Corn chips Plums -0.04
Crackers Plums -0.09
Cupcakes Plums 0.09
Danish Plums 0.22
Donuts Plums 0.11
Fruit rolls Plums 0.03
Graham crackers Plums -0.11
Granola bars Plums 0.05
Ice cream Plums 0.14
Muffins Plums 0.58
Pizza, from frozen Plums 0.38
Popsicles and bars Plums 0.09
Potato chips Plums 0.02
Pretzels Plums 0.00
Pudding, ready-to-eat Plums 0.13
Sandwich crackers Plums -0.05
Toaster pastries Plums 0.10
Tortilla chips Plums -0.04
Chocolate candy Raisins 0.05
Cookies Raisins -0.03
Corn chips Raisins 0.02
Crackers Raisins -0.03
Cupcakes Raisins 0.15
Danish Raisins 0.28
Donuts Raisins 0.17
Fruit rolls Raisins 0.09
Graham crackers Raisins -0.05
Granola bars Raisins 0.11
Ice cream Raisins 0.20
Muffins Raisins 0.64
Pizza, from frozen Raisins 0.44
Popsicles and bars Raisins 0.15
Potato chips Raisins 0.08
Pretzels Raisins 0.06
Pudding, ready-to-eat Raisins 0.19
Sandwich crackers Raisins 0.01
Toaster pastries Raisins 0.16
Tortilla chips Raisins 0.02
Chocolate candy Strawberries -0.17
Cookies Strawberries -0.25
Corn chips Strawberries -0.20
Crackers Strawberries -0.25
Cupcakes Strawberries -0.07
Danish Strawberries 0.06
Donuts Strawberries -0.05
Fruit rolls Strawberries -0.13
Graham crackers Strawberries -0.27
Granola bars Strawberries -0.11
Ice cream Strawberries -0.02
Muffins Strawberries 0.42
Pizza, from frozen Strawberries 0.22
Popsicles and bars Strawberries -0.07
Potato chips Strawberries -0.14
Pretzels Strawberries -0.16
Pudding, ready-to-eat Strawberries -0.03
Sandwich crackers Strawberries -0.21
Toaster pastries Strawberries -0.06
Tortilla chips Strawberries -0.20
Chocolate candy Tangerine -0.27
Cookies Tangerine -0.35
Corn chips Tangerine -0.30
Crackers Tangerine -0.35
Cupcakes Tangerine -0.17
Danish Tangerine -0.04
Donuts Tangerine -0.15
Fruit rolls Tangerine -0.23
Graham crackers Tangerine -0.37
Granola bars Tangerine -0.21
Ice cream Tangerine -0.12
Muffins Tangerine 0.32
Pizza, from frozen Tangerine 0.12
Popsicles and bars Tangerine -0.17
Potato chips Tangerine -0.24
Pretzels Tangerine -0.26
Pudding, ready-to-eat Tangerine -0.13
Sandwich crackers Tangerine -0.31
Toaster pastries Tangerine -0.16
Tortilla chips Tangerine -0.30
Chocolate candy Watermelon -0.01
Cookies Watermelon -0.09
Corn chips Watermelon -0.04
Crackers Watermelon -0.09
Cupcakes Watermelon 0.09
Danish Watermelon 0.22
Donuts Watermelon 0.11
Fruit rolls Watermelon 0.03
Graham crackers Watermelon -0.11
Granola bars Watermelon 0.05
Ice cream Watermelon 0.14
Muffins Watermelon 0.58
Pizza, from frozen Watermelon 0.38
Popsicles and bars Watermelon 0.09
Potato chips Watermelon 0.02
Pretzels Watermelon 0.00
Pudding, ready-to-eat Watermelon 0.13
Sandwich crackers Watermelon -0.05
Toaster pastries Watermelon 0.10
Tortilla chips Watermelon -0.04
Chocolate candy Broccoli 0.06
Cookies Broccoli -0.02
Corn chips Broccoli 0.03
Crackers Broccoli -0.02
Cupcakes Broccoli 0.16
Danish Broccoli 0.29
Donuts Broccoli 0.18
Fruit rolls Broccoli 0.10
Graham crackers Broccoli -0.04
Granola bars Broccoli 0.12
Ice cream Broccoli 0.21
Muffins Broccoli 0.65
Pizza, from frozen Broccoli 0.45
Popsicles and bars Broccoli 0.16
Potato chips Broccoli 0.09
Pretzels Broccoli 0.07
Pudding, ready-to-eat Broccoli 0.20
Sandwich crackers Broccoli 0.02
Toaster pastries Broccoli 0.17
Tortilla chips Broccoli 0.03
Chocolate candy Carrots 0.05
Cookies Carrots -0.03
Corn chips Carrots 0.02
Crackers Carrots -0.03
Cupcakes Carrots 0.15
Danish Carrots 0.28
Donuts Carrots 0.17
Fruit rolls Carrots 0.09
Graham crackers Carrots -0.05
Granola bars Carrots 0.11
Ice cream Carrots 0.20
Muffins Carrots 0.64
Pizza, from frozen Carrots 0.44
Popsicles and bars Carrots 0.15
Potato chips Carrots 0.08
Pretzels Carrots 0.06
Pudding, ready-to-eat Carrots 0.19
Sandwich crackers Carrots 0.01
Toaster pastries Carrots 0.16
Tortilla chips Carrots 0.02
Chocolate candy Celery 0.08
Cookies Celery 0.00
Corn chips Celery 0.05
Crackers Celery 0.00
Cupcakes Celery 0.18
Danish Celery 0.31
Donuts Celery 0.20
Fruit rolls Celery 0.12
Graham crackers Celery -0.02
Granola bars Celery 0.14
Ice cream Celery 0.23
Muffins Celery 0.67
Pizza, from frozen Celery 0.47
Popsicles and bars Celery 0.18
Potato chips Celery 0.11
Pretzels Celery 0.09
Pudding, ready-to-eat Celery 0.22
Sandwich crackers Celery 0.04
Toaster pastries Celery 0.19
Tortilla chips Celery 0.05
Chocolate candy Red.peppers -0.36
Cookies Red.peppers -0.44
Corn chips Red.peppers -0.39
Crackers Red.peppers -0.44
Cupcakes Red.peppers -0.26
Danish Red.peppers -0.13
Donuts Red.peppers -0.24
Fruit rolls Red.peppers -0.32
Graham crackers Red.peppers -0.46
Granola bars Red.peppers -0.30
Ice cream Red.peppers -0.21
Muffins Red.peppers 0.23
Pizza, from frozen Red.peppers 0.03
Popsicles and bars Red.peppers -0.26
Potato chips Red.peppers -0.33
Pretzels Red.peppers -0.35
Pudding, ready-to-eat Red.peppers -0.22
Sandwich crackers Red.peppers -0.40
Toaster pastries Red.peppers -0.25
Tortilla chips Red.peppers -0.39
Chocolate candy Sweet.potatoes..cooked -0.09
Cookies Sweet.potatoes..cooked -0.17
Corn chips Sweet.potatoes..cooked -0.12
Crackers Sweet.potatoes..cooked -0.17
Cupcakes Sweet.potatoes..cooked 0.01
Danish Sweet.potatoes..cooked 0.14
Donuts Sweet.potatoes..cooked 0.03
Fruit rolls Sweet.potatoes..cooked -0.05
Graham crackers Sweet.potatoes..cooked -0.19
Granola bars Sweet.potatoes..cooked -0.03
Ice cream Sweet.potatoes..cooked 0.06
Muffins Sweet.potatoes..cooked 0.50
Pizza, from frozen Sweet.potatoes..cooked 0.30
Popsicles and bars Sweet.potatoes..cooked 0.01
Potato chips Sweet.potatoes..cooked -0.06
Pretzels Sweet.potatoes..cooked -0.08
Pudding, ready-to-eat Sweet.potatoes..cooked 0.05
Sandwich crackers Sweet.potatoes..cooked -0.13
Toaster pastries Sweet.potatoes..cooked 0.02
Tortilla chips Sweet.potatoes..cooked -0.12
Chocolate candy Tomatoes..grape.or.cherry -0.31
Cookies Tomatoes..grape.or.cherry -0.39
Corn chips Tomatoes..grape.or.cherry -0.34
Crackers Tomatoes..grape.or.cherry -0.39
Cupcakes Tomatoes..grape.or.cherry -0.21
Danish Tomatoes..grape.or.cherry -0.08
Donuts Tomatoes..grape.or.cherry -0.19
Fruit rolls Tomatoes..grape.or.cherry -0.27
Graham crackers Tomatoes..grape.or.cherry -0.41
Granola bars Tomatoes..grape.or.cherry -0.25
Ice cream Tomatoes..grape.or.cherry -0.16
Muffins Tomatoes..grape.or.cherry 0.28
Pizza, from frozen Tomatoes..grape.or.cherry 0.08
Popsicles and bars Tomatoes..grape.or.cherry -0.21
Potato chips Tomatoes..grape.or.cherry -0.28
Pretzels Tomatoes..grape.or.cherry -0.30
Pudding, ready-to-eat Tomatoes..grape.or.cherry -0.17
Sandwich crackers Tomatoes..grape.or.cherry -0.35
Toaster pastries Tomatoes..grape.or.cherry -0.20
Tortilla chips Tomatoes..grape.or.cherry -0.34

Cleaning up ‘Comfort_Snack’ and ‘Healthy_Snack_Alternative’ variables -

### Clean up 'Comfort_Snack' column
snackCostDF$Comfort_Snack <-
  str_trim(
    ifelse(is.na(str_locate(snackCostDF$Comfort_Snack,"\\(")[,"start"]), snackCostDF$Comfort_Snack,str_sub(snackCostDF$Comfort_Snack, 1, str_locate(snackCostDF$Comfort_Snack,"\\(")[,"start"] - 1)
  )
)

### Cleanup 'Healthy_Snack_Alternative' column    
snackCostDF$Healthy_Snack_Alternative <-
  str_trim(
    str_replace(
      ifelse(is.na(str_locate(snackCostDF$Healthy_Snack_Alternative,"\\.\\.")[,"start"]),
             snackCostDF$Healthy_Snack_Alternative,{str_sub(snackCostDF$Healthy_Snack_Alternative, 1, str_locate(snackCostDF$Healthy_Snack_Alternative,"\\.\\.")[,"start"] - 1)}),"\\."," ")
    )

snackCostDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Healthy_Snack_Alternative Cost_Impact
Chocolate candy Apples -0.12
Cookies Apples -0.20
Corn chips Apples -0.15
Crackers Apples -0.20
Cupcakes Apples -0.02
Danish Apples 0.11
Donuts Apples 0.00
Fruit rolls Apples -0.08
Graham crackers Apples -0.22
Granola bars Apples -0.06
Ice cream Apples 0.03
Muffins Apples 0.47
Pizza, from frozen Apples 0.27
Popsicles and bars Apples -0.02
Potato chips Apples -0.09
Pretzels Apples -0.11
Pudding, ready-to-eat Apples 0.02
Sandwich crackers Apples -0.16
Toaster pastries Apples -0.01
Tortilla chips Apples -0.15
Chocolate candy Applesauce 0.02
Cookies Applesauce -0.06
Corn chips Applesauce -0.01
Crackers Applesauce -0.06
Cupcakes Applesauce 0.12
Danish Applesauce 0.25
Donuts Applesauce 0.14
Fruit rolls Applesauce 0.06
Graham crackers Applesauce -0.08
Granola bars Applesauce 0.08
Ice cream Applesauce 0.17
Muffins Applesauce 0.61
Pizza, from frozen Applesauce 0.41
Popsicles and bars Applesauce 0.12
Potato chips Applesauce 0.05
Pretzels Applesauce 0.03
Pudding, ready-to-eat Applesauce 0.16
Sandwich crackers Applesauce -0.02
Toaster pastries Applesauce 0.13
Tortilla chips Applesauce -0.01
Chocolate candy Bananas 0.06
Cookies Bananas -0.02
Corn chips Bananas 0.03
Crackers Bananas -0.02
Cupcakes Bananas 0.16
Danish Bananas 0.29
Donuts Bananas 0.18
Fruit rolls Bananas 0.10
Graham crackers Bananas -0.04
Granola bars Bananas 0.12
Ice cream Bananas 0.21
Muffins Bananas 0.65
Pizza, from frozen Bananas 0.45
Popsicles and bars Bananas 0.16
Potato chips Bananas 0.09
Pretzels Bananas 0.07
Pudding, ready-to-eat Bananas 0.20
Sandwich crackers Bananas 0.02
Toaster pastries Bananas 0.17
Tortilla chips Bananas 0.03
Chocolate candy Cantaloupe -0.14
Cookies Cantaloupe -0.22
Corn chips Cantaloupe -0.17
Crackers Cantaloupe -0.22
Cupcakes Cantaloupe -0.04
Danish Cantaloupe 0.09
Donuts Cantaloupe -0.02
Fruit rolls Cantaloupe -0.10
Graham crackers Cantaloupe -0.24
Granola bars Cantaloupe -0.08
Ice cream Cantaloupe 0.01
Muffins Cantaloupe 0.45
Pizza, from frozen Cantaloupe 0.25
Popsicles and bars Cantaloupe -0.04
Potato chips Cantaloupe -0.11
Pretzels Cantaloupe -0.13
Pudding, ready-to-eat Cantaloupe 0.00
Sandwich crackers Cantaloupe -0.18
Toaster pastries Cantaloupe -0.03
Tortilla chips Cantaloupe -0.17
Chocolate candy Fruit cocktail -0.07
Cookies Fruit cocktail -0.15
Corn chips Fruit cocktail -0.10
Crackers Fruit cocktail -0.15
Cupcakes Fruit cocktail 0.03
Danish Fruit cocktail 0.16
Donuts Fruit cocktail 0.05
Fruit rolls Fruit cocktail -0.03
Graham crackers Fruit cocktail -0.17
Granola bars Fruit cocktail -0.01
Ice cream Fruit cocktail 0.08
Muffins Fruit cocktail 0.52
Pizza, from frozen Fruit cocktail 0.32
Popsicles and bars Fruit cocktail 0.03
Potato chips Fruit cocktail -0.04
Pretzels Fruit cocktail -0.06
Pudding, ready-to-eat Fruit cocktail 0.07
Sandwich crackers Fruit cocktail -0.11
Toaster pastries Fruit cocktail 0.04
Tortilla chips Fruit cocktail -0.10
Chocolate candy Grapes -0.08
Cookies Grapes -0.16
Corn chips Grapes -0.11
Crackers Grapes -0.16
Cupcakes Grapes 0.02
Danish Grapes 0.15
Donuts Grapes 0.04
Fruit rolls Grapes -0.04
Graham crackers Grapes -0.18
Granola bars Grapes -0.02
Ice cream Grapes 0.07
Muffins Grapes 0.51
Pizza, from frozen Grapes 0.31
Popsicles and bars Grapes 0.02
Potato chips Grapes -0.05
Pretzels Grapes -0.07
Pudding, ready-to-eat Grapes 0.06
Sandwich crackers Grapes -0.12
Toaster pastries Grapes 0.03
Tortilla chips Grapes -0.11
Chocolate candy Oranges 0.04
Cookies Oranges -0.04
Corn chips Oranges 0.01
Crackers Oranges -0.04
Cupcakes Oranges 0.14
Danish Oranges 0.27
Donuts Oranges 0.16
Fruit rolls Oranges 0.08
Graham crackers Oranges -0.06
Granola bars Oranges 0.10
Ice cream Oranges 0.19
Muffins Oranges 0.63
Pizza, from frozen Oranges 0.43
Popsicles and bars Oranges 0.14
Potato chips Oranges 0.07
Pretzels Oranges 0.05
Pudding, ready-to-eat Oranges 0.18
Sandwich crackers Oranges 0.00
Toaster pastries Oranges 0.15
Tortilla chips Oranges 0.01
Chocolate candy Peaches -0.07
Cookies Peaches -0.15
Corn chips Peaches -0.10
Crackers Peaches -0.15
Cupcakes Peaches 0.03
Danish Peaches 0.16
Donuts Peaches 0.05
Fruit rolls Peaches -0.03
Graham crackers Peaches -0.17
Granola bars Peaches -0.01
Ice cream Peaches 0.08
Muffins Peaches 0.52
Pizza, from frozen Peaches 0.32
Popsicles and bars Peaches 0.03
Potato chips Peaches -0.04
Pretzels Peaches -0.06
Pudding, ready-to-eat Peaches 0.07
Sandwich crackers Peaches -0.11
Toaster pastries Peaches 0.04
Tortilla chips Peaches -0.10
Chocolate candy Pineapple -0.02
Cookies Pineapple -0.10
Corn chips Pineapple -0.05
Crackers Pineapple -0.10
Cupcakes Pineapple 0.08
Danish Pineapple 0.21
Donuts Pineapple 0.10
Fruit rolls Pineapple 0.02
Graham crackers Pineapple -0.12
Granola bars Pineapple 0.04
Ice cream Pineapple 0.13
Muffins Pineapple 0.57
Pizza, from frozen Pineapple 0.37
Popsicles and bars Pineapple 0.08
Potato chips Pineapple 0.01
Pretzels Pineapple -0.01
Pudding, ready-to-eat Pineapple 0.12
Sandwich crackers Pineapple -0.06
Toaster pastries Pineapple 0.09
Tortilla chips Pineapple -0.05
Chocolate candy Plums -0.01
Cookies Plums -0.09
Corn chips Plums -0.04
Crackers Plums -0.09
Cupcakes Plums 0.09
Danish Plums 0.22
Donuts Plums 0.11
Fruit rolls Plums 0.03
Graham crackers Plums -0.11
Granola bars Plums 0.05
Ice cream Plums 0.14
Muffins Plums 0.58
Pizza, from frozen Plums 0.38
Popsicles and bars Plums 0.09
Potato chips Plums 0.02
Pretzels Plums 0.00
Pudding, ready-to-eat Plums 0.13
Sandwich crackers Plums -0.05
Toaster pastries Plums 0.10
Tortilla chips Plums -0.04
Chocolate candy Raisins 0.05
Cookies Raisins -0.03
Corn chips Raisins 0.02
Crackers Raisins -0.03
Cupcakes Raisins 0.15
Danish Raisins 0.28
Donuts Raisins 0.17
Fruit rolls Raisins 0.09
Graham crackers Raisins -0.05
Granola bars Raisins 0.11
Ice cream Raisins 0.20
Muffins Raisins 0.64
Pizza, from frozen Raisins 0.44
Popsicles and bars Raisins 0.15
Potato chips Raisins 0.08
Pretzels Raisins 0.06
Pudding, ready-to-eat Raisins 0.19
Sandwich crackers Raisins 0.01
Toaster pastries Raisins 0.16
Tortilla chips Raisins 0.02
Chocolate candy Strawberries -0.17
Cookies Strawberries -0.25
Corn chips Strawberries -0.20
Crackers Strawberries -0.25
Cupcakes Strawberries -0.07
Danish Strawberries 0.06
Donuts Strawberries -0.05
Fruit rolls Strawberries -0.13
Graham crackers Strawberries -0.27
Granola bars Strawberries -0.11
Ice cream Strawberries -0.02
Muffins Strawberries 0.42
Pizza, from frozen Strawberries 0.22
Popsicles and bars Strawberries -0.07
Potato chips Strawberries -0.14
Pretzels Strawberries -0.16
Pudding, ready-to-eat Strawberries -0.03
Sandwich crackers Strawberries -0.21
Toaster pastries Strawberries -0.06
Tortilla chips Strawberries -0.20
Chocolate candy Tangerine -0.27
Cookies Tangerine -0.35
Corn chips Tangerine -0.30
Crackers Tangerine -0.35
Cupcakes Tangerine -0.17
Danish Tangerine -0.04
Donuts Tangerine -0.15
Fruit rolls Tangerine -0.23
Graham crackers Tangerine -0.37
Granola bars Tangerine -0.21
Ice cream Tangerine -0.12
Muffins Tangerine 0.32
Pizza, from frozen Tangerine 0.12
Popsicles and bars Tangerine -0.17
Potato chips Tangerine -0.24
Pretzels Tangerine -0.26
Pudding, ready-to-eat Tangerine -0.13
Sandwich crackers Tangerine -0.31
Toaster pastries Tangerine -0.16
Tortilla chips Tangerine -0.30
Chocolate candy Watermelon -0.01
Cookies Watermelon -0.09
Corn chips Watermelon -0.04
Crackers Watermelon -0.09
Cupcakes Watermelon 0.09
Danish Watermelon 0.22
Donuts Watermelon 0.11
Fruit rolls Watermelon 0.03
Graham crackers Watermelon -0.11
Granola bars Watermelon 0.05
Ice cream Watermelon 0.14
Muffins Watermelon 0.58
Pizza, from frozen Watermelon 0.38
Popsicles and bars Watermelon 0.09
Potato chips Watermelon 0.02
Pretzels Watermelon 0.00
Pudding, ready-to-eat Watermelon 0.13
Sandwich crackers Watermelon -0.05
Toaster pastries Watermelon 0.10
Tortilla chips Watermelon -0.04
Chocolate candy Broccoli 0.06
Cookies Broccoli -0.02
Corn chips Broccoli 0.03
Crackers Broccoli -0.02
Cupcakes Broccoli 0.16
Danish Broccoli 0.29
Donuts Broccoli 0.18
Fruit rolls Broccoli 0.10
Graham crackers Broccoli -0.04
Granola bars Broccoli 0.12
Ice cream Broccoli 0.21
Muffins Broccoli 0.65
Pizza, from frozen Broccoli 0.45
Popsicles and bars Broccoli 0.16
Potato chips Broccoli 0.09
Pretzels Broccoli 0.07
Pudding, ready-to-eat Broccoli 0.20
Sandwich crackers Broccoli 0.02
Toaster pastries Broccoli 0.17
Tortilla chips Broccoli 0.03
Chocolate candy Carrots 0.05
Cookies Carrots -0.03
Corn chips Carrots 0.02
Crackers Carrots -0.03
Cupcakes Carrots 0.15
Danish Carrots 0.28
Donuts Carrots 0.17
Fruit rolls Carrots 0.09
Graham crackers Carrots -0.05
Granola bars Carrots 0.11
Ice cream Carrots 0.20
Muffins Carrots 0.64
Pizza, from frozen Carrots 0.44
Popsicles and bars Carrots 0.15
Potato chips Carrots 0.08
Pretzels Carrots 0.06
Pudding, ready-to-eat Carrots 0.19
Sandwich crackers Carrots 0.01
Toaster pastries Carrots 0.16
Tortilla chips Carrots 0.02
Chocolate candy Celery 0.08
Cookies Celery 0.00
Corn chips Celery 0.05
Crackers Celery 0.00
Cupcakes Celery 0.18
Danish Celery 0.31
Donuts Celery 0.20
Fruit rolls Celery 0.12
Graham crackers Celery -0.02
Granola bars Celery 0.14
Ice cream Celery 0.23
Muffins Celery 0.67
Pizza, from frozen Celery 0.47
Popsicles and bars Celery 0.18
Potato chips Celery 0.11
Pretzels Celery 0.09
Pudding, ready-to-eat Celery 0.22
Sandwich crackers Celery 0.04
Toaster pastries Celery 0.19
Tortilla chips Celery 0.05
Chocolate candy Red peppers -0.36
Cookies Red peppers -0.44
Corn chips Red peppers -0.39
Crackers Red peppers -0.44
Cupcakes Red peppers -0.26
Danish Red peppers -0.13
Donuts Red peppers -0.24
Fruit rolls Red peppers -0.32
Graham crackers Red peppers -0.46
Granola bars Red peppers -0.30
Ice cream Red peppers -0.21
Muffins Red peppers 0.23
Pizza, from frozen Red peppers 0.03
Popsicles and bars Red peppers -0.26
Potato chips Red peppers -0.33
Pretzels Red peppers -0.35
Pudding, ready-to-eat Red peppers -0.22
Sandwich crackers Red peppers -0.40
Toaster pastries Red peppers -0.25
Tortilla chips Red peppers -0.39
Chocolate candy Sweet potatoes -0.09
Cookies Sweet potatoes -0.17
Corn chips Sweet potatoes -0.12
Crackers Sweet potatoes -0.17
Cupcakes Sweet potatoes 0.01
Danish Sweet potatoes 0.14
Donuts Sweet potatoes 0.03
Fruit rolls Sweet potatoes -0.05
Graham crackers Sweet potatoes -0.19
Granola bars Sweet potatoes -0.03
Ice cream Sweet potatoes 0.06
Muffins Sweet potatoes 0.50
Pizza, from frozen Sweet potatoes 0.30
Popsicles and bars Sweet potatoes 0.01
Potato chips Sweet potatoes -0.06
Pretzels Sweet potatoes -0.08
Pudding, ready-to-eat Sweet potatoes 0.05
Sandwich crackers Sweet potatoes -0.13
Toaster pastries Sweet potatoes 0.02
Tortilla chips Sweet potatoes -0.12
Chocolate candy Tomatoes -0.31
Cookies Tomatoes -0.39
Corn chips Tomatoes -0.34
Crackers Tomatoes -0.39
Cupcakes Tomatoes -0.21
Danish Tomatoes -0.08
Donuts Tomatoes -0.19
Fruit rolls Tomatoes -0.27
Graham crackers Tomatoes -0.41
Granola bars Tomatoes -0.25
Ice cream Tomatoes -0.16
Muffins Tomatoes 0.28
Pizza, from frozen Tomatoes 0.08
Popsicles and bars Tomatoes -0.21
Potato chips Tomatoes -0.28
Pretzels Tomatoes -0.30
Pudding, ready-to-eat Tomatoes -0.17
Sandwich crackers Tomatoes -0.35
Toaster pastries Tomatoes -0.20
Tortilla chips Tomatoes -0.34
  1. Merge both Calorie and Cost Impact data frames into one consolidated tidy data frame:
snackDF <- inner_join(snackCalorieDF,snackCostDF)
## Joining, by = c("Comfort_Snack", "Healthy_Snack_Alternative")
snackDF %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Comfort_Snack Healthy_Snack_Alternative Calorie_Impact Cost_Impact
Chocolate candy Apples 185 -0.12
Cookies Apples 46 -0.20
Corn chips Apples 63 -0.15
Crackers Apples 37 -0.20
Cupcakes Apples 97 -0.02
Danish Apples 194 0.11
Donuts Apples 158 0.00
Fruit rolls Apples 5 -0.08
Graham crackers Apples 25 -0.22
Granola bars Apples 42 -0.06
Ice cream Apples 119 0.03
Muffins Apples 292 0.47
Pizza, from frozen Apples 175 0.27
Popsicles and bars Apples 3 -0.02
Potato chips Apples 92 -0.09
Pretzels Apples 91 -0.11
Pudding, ready-to-eat Apples 75 0.02
Sandwich crackers Apples 106 -0.16
Toaster pastries Apples 222 -0.01
Tortilla chips Apples 84 -0.15
Chocolate candy Applesauce 162 0.02
Cookies Applesauce 23 -0.06
Corn chips Applesauce 40 -0.01
Crackers Applesauce 14 -0.06
Cupcakes Applesauce 74 0.12
Danish Applesauce 171 0.25
Donuts Applesauce 135 0.14
Fruit rolls Applesauce -18 0.06
Graham crackers Applesauce 2 -0.08
Granola bars Applesauce 19 0.08
Ice cream Applesauce 96 0.17
Muffins Applesauce 269 0.61
Pizza, from frozen Applesauce 152 0.41
Popsicles and bars Applesauce -20 0.12
Potato chips Applesauce 69 0.05
Pretzels Applesauce 68 0.03
Pudding, ready-to-eat Applesauce 52 0.16
Sandwich crackers Applesauce 83 -0.02
Toaster pastries Applesauce 199 0.13
Tortilla chips Applesauce 61 -0.01
Chocolate candy Bananas 160 0.06
Cookies Bananas 21 -0.02
Corn chips Bananas 38 0.03
Crackers Bananas 12 -0.02
Cupcakes Bananas 72 0.16
Danish Bananas 169 0.29
Donuts Bananas 133 0.18
Fruit rolls Bananas -20 0.10
Graham crackers Bananas 0 -0.04
Granola bars Bananas 17 0.12
Ice cream Bananas 94 0.21
Muffins Bananas 267 0.65
Pizza, from frozen Bananas 150 0.45
Popsicles and bars Bananas -22 0.16
Potato chips Bananas 67 0.09
Pretzels Bananas 66 0.07
Pudding, ready-to-eat Bananas 50 0.20
Sandwich crackers Bananas 81 0.02
Toaster pastries Bananas 197 0.17
Tortilla chips Bananas 59 0.03
Chocolate candy Cantaloupe 229 -0.14
Cookies Cantaloupe 90 -0.22
Corn chips Cantaloupe 107 -0.17
Crackers Cantaloupe 81 -0.22
Cupcakes Cantaloupe 141 -0.04
Danish Cantaloupe 238 0.09
Donuts Cantaloupe 202 -0.02
Fruit rolls Cantaloupe 49 -0.10
Graham crackers Cantaloupe 69 -0.24
Granola bars Cantaloupe 86 -0.08
Ice cream Cantaloupe 163 0.01
Muffins Cantaloupe 336 0.45
Pizza, from frozen Cantaloupe 219 0.25
Popsicles and bars Cantaloupe 47 -0.04
Potato chips Cantaloupe 136 -0.11
Pretzels Cantaloupe 135 -0.13
Pudding, ready-to-eat Cantaloupe 119 0.00
Sandwich crackers Cantaloupe 150 -0.18
Toaster pastries Cantaloupe 266 -0.03
Tortilla chips Cantaloupe 128 -0.17
Chocolate candy Fruit cocktail 191 -0.07
Cookies Fruit cocktail 52 -0.15
Corn chips Fruit cocktail 69 -0.10
Crackers Fruit cocktail 43 -0.15
Cupcakes Fruit cocktail 103 0.03
Danish Fruit cocktail 200 0.16
Donuts Fruit cocktail 164 0.05
Fruit rolls Fruit cocktail 11 -0.03
Graham crackers Fruit cocktail 31 -0.17
Granola bars Fruit cocktail 48 -0.01
Ice cream Fruit cocktail 125 0.08
Muffins Fruit cocktail 298 0.52
Pizza, from frozen Fruit cocktail 181 0.32
Popsicles and bars Fruit cocktail 9 0.03
Potato chips Fruit cocktail 98 -0.04
Pretzels Fruit cocktail 97 -0.06
Pudding, ready-to-eat Fruit cocktail 81 0.07
Sandwich crackers Fruit cocktail 112 -0.11
Toaster pastries Fruit cocktail 228 0.04
Tortilla chips Fruit cocktail 90 -0.10
Chocolate candy Grapes 203 -0.08
Cookies Grapes 64 -0.16
Corn chips Grapes 81 -0.11
Crackers Grapes 55 -0.16
Cupcakes Grapes 115 0.02
Danish Grapes 212 0.15
Donuts Grapes 176 0.04
Fruit rolls Grapes 23 -0.04
Graham crackers Grapes 43 -0.18
Granola bars Grapes 60 -0.02
Ice cream Grapes 137 0.07
Muffins Grapes 310 0.51
Pizza, from frozen Grapes 193 0.31
Popsicles and bars Grapes 21 0.02
Potato chips Grapes 110 -0.05
Pretzels Grapes 109 -0.07
Pudding, ready-to-eat Grapes 93 0.06
Sandwich crackers Grapes 124 -0.12
Toaster pastries Grapes 240 0.03
Tortilla chips Grapes 102 -0.11
Chocolate candy Oranges 209 0.04
Cookies Oranges 70 -0.04
Corn chips Oranges 87 0.01
Crackers Oranges 61 -0.04
Cupcakes Oranges 121 0.14
Danish Oranges 218 0.27
Donuts Oranges 182 0.16
Fruit rolls Oranges 29 0.08
Graham crackers Oranges 49 -0.06
Granola bars Oranges 66 0.10
Ice cream Oranges 143 0.19
Muffins Oranges 316 0.63
Pizza, from frozen Oranges 199 0.43
Popsicles and bars Oranges 27 0.14
Potato chips Oranges 116 0.07
Pretzels Oranges 115 0.05
Pudding, ready-to-eat Oranges 99 0.18
Sandwich crackers Oranges 130 0.00
Toaster pastries Oranges 246 0.15
Tortilla chips Oranges 108 0.01
Chocolate candy Peaches 194 -0.07
Cookies Peaches 55 -0.15
Corn chips Peaches 72 -0.10
Crackers Peaches 46 -0.15
Cupcakes Peaches 106 0.03
Danish Peaches 203 0.16
Donuts Peaches 167 0.05
Fruit rolls Peaches 14 -0.03
Graham crackers Peaches 34 -0.17
Granola bars Peaches 51 -0.01
Ice cream Peaches 128 0.08
Muffins Peaches 301 0.52
Pizza, from frozen Peaches 184 0.32
Popsicles and bars Peaches 12 0.03
Potato chips Peaches 101 -0.04
Pretzels Peaches 100 -0.06
Pudding, ready-to-eat Peaches 84 0.07
Sandwich crackers Peaches 115 -0.11
Toaster pastries Peaches 231 0.04
Tortilla chips Peaches 93 -0.10
Chocolate candy Pineapple 187 -0.02
Cookies Pineapple 48 -0.10
Corn chips Pineapple 65 -0.05
Crackers Pineapple 39 -0.10
Cupcakes Pineapple 99 0.08
Danish Pineapple 196 0.21
Donuts Pineapple 160 0.10
Fruit rolls Pineapple 7 0.02
Graham crackers Pineapple 27 -0.12
Granola bars Pineapple 44 0.04
Ice cream Pineapple 121 0.13
Muffins Pineapple 294 0.57
Pizza, from frozen Pineapple 177 0.37
Popsicles and bars Pineapple 5 0.08
Potato chips Pineapple 94 0.01
Pretzels Pineapple 93 -0.01
Pudding, ready-to-eat Pineapple 77 0.12
Sandwich crackers Pineapple 108 -0.06
Toaster pastries Pineapple 224 0.09
Tortilla chips Pineapple 86 -0.05
Chocolate candy Plums 224 -0.01
Cookies Plums 85 -0.09
Corn chips Plums 102 -0.04
Crackers Plums 76 -0.09
Cupcakes Plums 136 0.09
Danish Plums 233 0.22
Donuts Plums 197 0.11
Fruit rolls Plums 44 0.03
Graham crackers Plums 64 -0.11
Granola bars Plums 81 0.05
Ice cream Plums 158 0.14
Muffins Plums 331 0.58
Pizza, from frozen Plums 214 0.38
Popsicles and bars Plums 42 0.09
Potato chips Plums 131 0.02
Pretzels Plums 130 0.00
Pudding, ready-to-eat Plums 114 0.13
Sandwich crackers Plums 145 -0.05
Toaster pastries Plums 261 0.10
Tortilla chips Plums 123 -0.04
Chocolate candy Raisins 153 0.05
Cookies Raisins 14 -0.03
Corn chips Raisins 31 0.02
Crackers Raisins 5 -0.03
Cupcakes Raisins 65 0.15
Danish Raisins 162 0.28
Donuts Raisins 126 0.17
Fruit rolls Raisins -27 0.09
Graham crackers Raisins -7 -0.05
Granola bars Raisins 10 0.11
Ice cream Raisins 87 0.20
Muffins Raisins 260 0.64
Pizza, from frozen Raisins 143 0.44
Popsicles and bars Raisins -29 0.15
Potato chips Raisins 60 0.08
Pretzels Raisins 59 0.06
Pudding, ready-to-eat Raisins 43 0.19
Sandwich crackers Raisins 74 0.01
Toaster pastries Raisins 190 0.16
Tortilla chips Raisins 52 0.02
Chocolate candy Strawberries 235 -0.17
Cookies Strawberries 96 -0.25
Corn chips Strawberries 113 -0.20
Crackers Strawberries 87 -0.25
Cupcakes Strawberries 147 -0.07
Danish Strawberries 244 0.06
Donuts Strawberries 208 -0.05
Fruit rolls Strawberries 55 -0.13
Graham crackers Strawberries 75 -0.27
Granola bars Strawberries 92 -0.11
Ice cream Strawberries 169 -0.02
Muffins Strawberries 342 0.42
Pizza, from frozen Strawberries 225 0.22
Popsicles and bars Strawberries 53 -0.07
Potato chips Strawberries 142 -0.14
Pretzels Strawberries 141 -0.16
Pudding, ready-to-eat Strawberries 125 -0.03
Sandwich crackers Strawberries 156 -0.21
Toaster pastries Strawberries 272 -0.06
Tortilla chips Strawberries 134 -0.20
Chocolate candy Tangerine 190 -0.27
Cookies Tangerine 51 -0.35
Corn chips Tangerine 68 -0.30
Crackers Tangerine 42 -0.35
Cupcakes Tangerine 102 -0.17
Danish Tangerine 199 -0.04
Donuts Tangerine 163 -0.15
Fruit rolls Tangerine 10 -0.23
Graham crackers Tangerine 30 -0.37
Granola bars Tangerine 47 -0.21
Ice cream Tangerine 124 -0.12
Muffins Tangerine 297 0.32
Pizza, from frozen Tangerine 180 0.12
Popsicles and bars Tangerine 8 -0.17
Potato chips Tangerine 97 -0.24
Pretzels Tangerine 96 -0.26
Pudding, ready-to-eat Tangerine 80 -0.13
Sandwich crackers Tangerine 111 -0.31
Toaster pastries Tangerine 227 -0.16
Tortilla chips Tangerine 89 -0.30
Chocolate candy Watermelon 188 -0.01
Cookies Watermelon 49 -0.09
Corn chips Watermelon 66 -0.04
Crackers Watermelon 40 -0.09
Cupcakes Watermelon 100 0.09
Danish Watermelon 197 0.22
Donuts Watermelon 161 0.11
Fruit rolls Watermelon 8 0.03
Graham crackers Watermelon 28 -0.11
Granola bars Watermelon 45 0.05
Ice cream Watermelon 122 0.14
Muffins Watermelon 295 0.58
Pizza, from frozen Watermelon 178 0.38
Popsicles and bars Watermelon 6 0.09
Potato chips Watermelon 95 0.02
Pretzels Watermelon 94 0.00
Pudding, ready-to-eat Watermelon 78 0.13
Sandwich crackers Watermelon 109 -0.05
Toaster pastries Watermelon 225 0.10
Tortilla chips Watermelon 87 -0.04
Chocolate candy Broccoli 250 0.06
Cookies Broccoli 111 -0.02
Corn chips Broccoli 128 0.03
Crackers Broccoli 102 -0.02
Cupcakes Broccoli 162 0.16
Danish Broccoli 259 0.29
Donuts Broccoli 223 0.18
Fruit rolls Broccoli 70 0.10
Graham crackers Broccoli 90 -0.04
Granola bars Broccoli 107 0.12
Ice cream Broccoli 184 0.21
Muffins Broccoli 357 0.65
Pizza, from frozen Broccoli 240 0.45
Popsicles and bars Broccoli 68 0.16
Potato chips Broccoli 157 0.09
Pretzels Broccoli 156 0.07
Pudding, ready-to-eat Broccoli 140 0.20
Sandwich crackers Broccoli 171 0.02
Toaster pastries Broccoli 287 0.17
Tortilla chips Broccoli 149 0.03
Chocolate candy Carrots 240 0.05
Cookies Carrots 101 -0.03
Corn chips Carrots 118 0.02
Crackers Carrots 92 -0.03
Cupcakes Carrots 152 0.15
Danish Carrots 249 0.28
Donuts Carrots 213 0.17
Fruit rolls Carrots 60 0.09
Graham crackers Carrots 80 -0.05
Granola bars Carrots 97 0.11
Ice cream Carrots 174 0.20
Muffins Carrots 347 0.64
Pizza, from frozen Carrots 230 0.44
Popsicles and bars Carrots 58 0.15
Potato chips Carrots 147 0.08
Pretzels Carrots 146 0.06
Pudding, ready-to-eat Carrots 130 0.19
Sandwich crackers Carrots 161 0.01
Toaster pastries Carrots 277 0.16
Tortilla chips Carrots 139 0.02
Chocolate candy Celery 252 0.08
Cookies Celery 113 0.00
Corn chips Celery 130 0.05
Crackers Celery 104 0.00
Cupcakes Celery 164 0.18
Danish Celery 261 0.31
Donuts Celery 225 0.20
Fruit rolls Celery 72 0.12
Graham crackers Celery 92 -0.02
Granola bars Celery 109 0.14
Ice cream Celery 186 0.23
Muffins Celery 359 0.67
Pizza, from frozen Celery 242 0.47
Popsicles and bars Celery 70 0.18
Potato chips Celery 159 0.11
Pretzels Celery 158 0.09
Pudding, ready-to-eat Celery 142 0.22
Sandwich crackers Celery 173 0.04
Toaster pastries Celery 289 0.19
Tortilla chips Celery 151 0.05
Chocolate candy Sweet potatoes 172 -0.09
Cookies Sweet potatoes 33 -0.17
Corn chips Sweet potatoes 50 -0.12
Crackers Sweet potatoes 24 -0.17
Cupcakes Sweet potatoes 84 0.01
Danish Sweet potatoes 181 0.14
Donuts Sweet potatoes 145 0.03
Fruit rolls Sweet potatoes -8 -0.05
Graham crackers Sweet potatoes 12 -0.19
Granola bars Sweet potatoes 29 -0.03
Ice cream Sweet potatoes 106 0.06
Muffins Sweet potatoes 279 0.50
Pizza, from frozen Sweet potatoes 162 0.30
Popsicles and bars Sweet potatoes -10 0.01
Potato chips Sweet potatoes 79 -0.06
Pretzels Sweet potatoes 78 -0.08
Pudding, ready-to-eat Sweet potatoes 62 0.05
Sandwich crackers Sweet potatoes 93 -0.13
Toaster pastries Sweet potatoes 209 0.02
Tortilla chips Sweet potatoes 71 -0.12
Chocolate candy Tomatoes 246 -0.31
Cookies Tomatoes 107 -0.39
Corn chips Tomatoes 124 -0.34
Crackers Tomatoes 98 -0.39
Cupcakes Tomatoes 158 -0.21
Danish Tomatoes 255 -0.08
Donuts Tomatoes 219 -0.19
Fruit rolls Tomatoes 66 -0.27
Graham crackers Tomatoes 86 -0.41
Granola bars Tomatoes 103 -0.25
Ice cream Tomatoes 180 -0.16
Muffins Tomatoes 353 0.28
Pizza, from frozen Tomatoes 236 0.08
Popsicles and bars Tomatoes 64 -0.21
Potato chips Tomatoes 153 -0.28
Pretzels Tomatoes 152 -0.30
Pudding, ready-to-eat Tomatoes 136 -0.17
Sandwich crackers Tomatoes 167 -0.35
Toaster pastries Tomatoes 283 -0.20
Tortilla chips Tomatoes 145 -0.34
  1. Analysis on the USDA Snack Substitution data set:

Healthy Snack : Average Calorie Impact

healthySnackDF <- snackDF %>% group_by(Healthy_Snack_Alternative) %>% summarise(Avg_Calorie_Impact = mean(Calorie_Impact),Total_Cost_Impact = sum(Cost_Impact)) 

ggplot(healthySnackDF, aes(x = reorder(Healthy_Snack_Alternative,Avg_Calorie_Impact), y = Avg_Calorie_Impact)) + 
  geom_bar(stat = "identity", position = "dodge", fill = "steelblue") + 
  geom_text(aes(label=round(Avg_Calorie_Impact,1)), hjust=-0.5, color="black", position = position_dodge(0.9), size=3.5) +
  scale_fill_brewer(palette="Paired") + 
  theme(axis.text.x=element_text(angle = 0, vjust = 0.5)) +
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Top Healthy Snack Alternatives based on Average Calorie Impact") +
  xlab("Healthy Snack Alternative") +  ylab ("Average Calorie Impact") +
  coord_flip()

Healthy Snack : Total Cost Impact

### Derive a Cost Impact indicator variable
healthySnackDF$CostImpact = ifelse(healthySnackDF$Total_Cost_Impact >= 0, "above", "below")

ggplot(healthySnackDF, aes(x = reorder(Healthy_Snack_Alternative,Total_Cost_Impact), y = Total_Cost_Impact)) +
  geom_bar(stat = "identity", position = "dodge",aes(fill = CostImpact)) +
  scale_fill_manual(name="Cost Impact", 
                   labels = c("Less Costly Substitue", "More Costly Substitute"), 
                   values = c("above"="#00ba38", "below"="#f8766d")) + 
  ggtitle("Top Healthy Snack Alternatives based on Cost Impact") +
  theme(plot.title = element_text(hjust = 0.5),legend.position = "bottom") +
  xlab("Healthy Snack Alternative") +  ylab ("Total Cost Impact") +
  coord_flip()

Conclusion:
  • Amongst vegetables => Celery, Broccoli and Carrots are the top most Calorie contributing healthy snack alternatives and more affordable compared to comfort snacks.
  • Tomatoes are better in terms of positive calorie impact, but are more costly healthy snack alternative
  • Amongst fruits => plums, Oranges, Bananas, Raisins, Applesauce are the top most Calorie contributing healthy snack alternatives and more affordable compared to comfort snacks.
  • Strawberries, Cantaloupes, Tangerines, Apples are better in terms of positive calorie impact, but are more costly healthy snack alternative