library(kableExtra)
library(stringr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
## 
##     group_rows
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
library(ggthemes)
library(readxl)
library(ggplot2)
theme_set(theme_classic())

Reading the dataset(Excel File) - Description about the dataset.

I have collected this data from https://www.ers.usda.gov/data-products/fruit-and-vegetable-prices/fruit-and-vegetable-prices/. I have chosen topic in USDA as Snacks -Impact on food costs of substituting fruits and vegetables for other snack foods and Snacks-Impact on caloric intake of substituting fruits and vegetables for other snack foods(2 data set). This data set is violating the tidy principles as the data (column names Apples, Tomatoes etc) represent values of the Healthy items as each column variable and each row represents two observations, not one. Each column is a individual item of Fruits and Vegetables and the cells are the value of the variable for the table. I have converted this untidy(messy) dataset into tidy by applying pivot_longer() function. After conversion this data set contains Fruits and Vegetables substitute for the given snacks and also their cost and calorie impact upon substitution. A negative sign in the cost data set means that food costs increase when the snack is replaced with a fruit or vegetable. For this analysis I have taken 4 columns after tidying up the data set- 1) Snacks- Snacks which are usually consumed by the customer. 2) Healthy Items - Fruits and Vegetables alternative for the snacks 3) Calorie - Average calorie replacing each snack with all fruits and vegetables 4) Cost - Total Cost replacing each snack with all fruits and vegetables

df_snacks_calories <- read_excel("caloricimpacts.xls", col_names = TRUE)
## New names:
## • `` -> `...1`
## • `` -> `...2`
df_snacks_calories
## # A tibble: 26 × 23
##    ...1      ...2  Apples Apple…¹ Bananas Canta…² Fruit…³ Grapes Oranges Peach…⁴
##    <chr>     <chr>  <dbl>   <dbl>   <dbl>   <dbl>   <dbl>  <dbl>   <dbl>   <dbl>
##  1 <NA>      Calo…     77     100     102      33      71     59      53      68
##  2 Chocolat… 262      185     162     160     229     191    203     209     194
##  3 Cookies … 123       46      23      21      90      52     64      70      55
##  4 Corn chi… 140       63      40      38     107      69     81      87      72
##  5 Crackers… 114       37      14      12      81      43     55      61      46
##  6 Cupcakes… 174       97      74      72     141     103    115     121     106
##  7 Danish (… 271      194     171     169     238     200    212     218     203
##  8 Donuts (… 235      158     135     133     202     164    176     182     167
##  9 Fruit ro… 82         5     -18     -20      49      11     23      29      14
## 10 Graham c… 102       25       2       0      69      31     43      49      34
## # … with 16 more rows, 13 more variables: `Pineapple (juice pack)` <dbl>,
## #   Plums <dbl>, Raisins <dbl>, Strawberries <dbl>, Tangerine <dbl>,
## #   Watermelon <dbl>, Broccoli <dbl>, Carrots <dbl>, Celery <dbl>,
## #   `Red Peppers` <dbl>, `Sweet potatoes` <dbl>, Tomatoes <dbl>,
## #   `Average change in calories of replacing each snack with all fruits and vegetables` <dbl>,
## #   and abbreviated variable names ¹​`Applesauce (sweetened)`, ²​Cantaloupe,
## #   ³​`Fruit cocktail (in light syrup)`, ⁴​`Peaches (in light syrup)`
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
glimpse(df_snacks_calories)
## Rows: 26
## Columns: 23
## $ ...1                                                                                <chr> …
## $ ...2                                                                                <chr> …
## $ Apples                                                                              <dbl> …
## $ `Applesauce (sweetened)`                                                            <dbl> …
## $ Bananas                                                                             <dbl> …
## $ Cantaloupe                                                                          <dbl> …
## $ `Fruit cocktail (in light syrup)`                                                   <dbl> …
## $ Grapes                                                                              <dbl> …
## $ Oranges                                                                             <dbl> …
## $ `Peaches (in light syrup)`                                                          <dbl> …
## $ `Pineapple (juice pack)`                                                            <dbl> …
## $ Plums                                                                               <dbl> …
## $ Raisins                                                                             <dbl> …
## $ Strawberries                                                                        <dbl> …
## $ Tangerine                                                                           <dbl> …
## $ Watermelon                                                                          <dbl> …
## $ Broccoli                                                                            <dbl> …
## $ Carrots                                                                             <dbl> …
## $ Celery                                                                              <dbl> …
## $ `Red Peppers`                                                                       <dbl> …
## $ `Sweet potatoes`                                                                    <dbl> …
## $ Tomatoes                                                                            <dbl> …
## $ `Average change in calories of replacing each snack with all fruits and vegetables` <dbl> …
df_snacks_cost <- read_excel("costimpacts.xls", col_names = TRUE)
## New names:
## • `` -> `...1`
## • `` -> `...2`
df_snacks_cost
## # A tibble: 25 × 23
##    ...1    ...2   Apples Apple…¹ Bananas Canta…² Fruit…³  Grapes Oranges Peach…⁴
##    <chr>   <chr>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
##  1 <NA>    pric…  0.36    0.22    0.18    0.38    0.31    0.32    0.2     0.31  
##  2 Chocol… 0.23… -0.12    0.0200  0.06   -0.14   -0.07   -0.08    0.0400 -0.07  
##  3 Cookies 0.16  -0.2    -0.06   -0.0200 -0.22   -0.15   -0.16   -0.04   -0.15  
##  4 Corn c… 0.20… -0.15   -0.0100  0.03   -0.17   -0.1    -0.11    0.0100 -0.1   
##  5 Cracke… 0.16  -0.2    -0.06   -0.0200 -0.22   -0.15   -0.16   -0.04   -0.15  
##  6 Cupcak… 0.34… -0.0200  0.12    0.16   -0.0400  0.0300  0.0200  0.14    0.0300
##  7 Danish  0.46…  0.11    0.25    0.29    0.09    0.16    0.15    0.27    0.16  
##  8 Donuts  0.35…  0       0.14    0.18   -0.0200  0.05    0.0400  0.16    0.05  
##  9 Fruit … 0.28… -0.0800  0.06    0.1    -0.1    -0.0300 -0.0400  0.08   -0.0300
## 10 Graham… 0.14… -0.22   -0.08   -0.0400 -0.24   -0.17   -0.18   -0.06   -0.17  
## # … with 15 more rows, 13 more variables: `Pineapple, canned` <dbl>,
## #   Plums <dbl>, Raisins <dbl>, Strawberries <dbl>, Tangerine <dbl>,
## #   Watermelon <dbl>, Broccoli <dbl>, Carrots <dbl>, Celery <dbl>,
## #   `Red peppers` <dbl>, `Sweet potatoes, cooked` <dbl>,
## #   `Tomatoes, grape or cherry` <dbl>,
## #   `Total cost of replacing each snack with all fruits and vegetables` <dbl>,
## #   and abbreviated variable names ¹​`Applesauce, jarred`, ²​Cantaloupe, …
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
glimpse(df_snacks_cost)
## Rows: 25
## Columns: 23
## $ ...1                                                                <chr> NA…
## $ ...2                                                                <chr> "p…
## $ Apples                                                              <dbl> 0.…
## $ `Applesauce, jarred`                                                <dbl> 0.…
## $ Bananas                                                             <dbl> 0.…
## $ Cantaloupe                                                          <dbl> 0.…
## $ `Fruit cocktail, canned`                                            <dbl> 0.…
## $ Grapes                                                              <dbl> 0.…
## $ Oranges                                                             <dbl> 0.…
## $ `Peaches, canned`                                                   <dbl> 0.…
## $ `Pineapple, canned`                                                 <dbl> 0.…
## $ Plums                                                               <dbl> 0.…
## $ Raisins                                                             <dbl> 0.…
## $ Strawberries                                                        <dbl> 0.…
## $ Tangerine                                                           <dbl> 0.…
## $ Watermelon                                                          <dbl> 0.…
## $ Broccoli                                                            <dbl> 0.…
## $ Carrots                                                             <dbl> 0.…
## $ Celery                                                              <dbl> 0.…
## $ `Red peppers`                                                       <dbl> 0.…
## $ `Sweet potatoes, cooked`                                            <dbl> 0.…
## $ `Tomatoes, grape or cherry`                                         <dbl> 0.…
## $ `Total cost of replacing each snack with all fruits and vegetables` <dbl> NA…

Changing the column names to Snacks and displaying the untidy dataset

names(df_snacks_calories)[1] <- "Snacks"

names(df_snacks_cost)[1] <- "Snacks"

head(df_snacks_calories) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks …2 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
NA Calories/ portion 77 100 102 33 71 59 53 68 75 38 109 27 72 74 12 22 10 23 90 16 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.45
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.45
Corn chips 140 63 40 38 107 69 81 87 72 65 102 31 113 68 66 128 118 130 117 50 124 83.45
Crackers (wheat) 114 37 14 12 81 43 55 61 46 39 76 5 87 42 40 102 92 104 91 24 98 57.45
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.45
head(df_snacks_cost) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks …2 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
NA 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
Chocolate candy 0.23999999999999999 -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
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
Corn chips 0.20999999999999999 -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
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
Cupcakes 0.34000000000000002 -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

Applying Pivot_longer()

df1=df_snacks_calories %>%   
  pivot_longer(c(`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`), names_to = "Healthy_items", values_to = "Calorie")

df2=df_snacks_cost %>%   
  pivot_longer(c(`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`), names_to = "Healthy_items", values_to = "Cost")
head(df1) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks …2 Average change in calories of replacing each snack with all fruits and vegetables Healthy_items Calorie
NA Calories/ portion NA Apples 77
NA Calories/ portion NA Applesauce (sweetened) 100
NA Calories/ portion NA Bananas 102
NA Calories/ portion NA Cantaloupe 33
NA Calories/ portion NA Fruit cocktail (in light syrup) 71
NA Calories/ portion NA Grapes 59
head(df2) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks …2 Total cost of replacing each snack with all fruits and vegetables Healthy_items Cost
NA price/portion NA Apples 0.36
NA price/portion NA Applesauce, jarred 0.22
NA price/portion NA Bananas 0.18
NA price/portion NA Cantaloupe 0.38
NA price/portion NA Fruit cocktail, canned 0.31
NA price/portion NA Grapes 0.32

Omitting na values

df1 = na.omit(df1)
df1 = subset(df1, select = c(`Snacks`,`Healthy_items`,`Calorie`))

df2 = na.omit(df2)
df2 = subset(df2, select = c(`Snacks`,`Healthy_items`,`Cost`))
head(df1) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks Healthy_items Calorie
Chocolate candy (milk chocolate candies) Apples 185
Chocolate candy (milk chocolate candies) Applesauce (sweetened) 162
Chocolate candy (milk chocolate candies) Bananas 160
Chocolate candy (milk chocolate candies) Cantaloupe 229
Chocolate candy (milk chocolate candies) Fruit cocktail (in light syrup) 191
Chocolate candy (milk chocolate candies) Grapes 203
head(df2) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks Healthy_items Cost
Chocolate candy Apples -0.12
Chocolate candy Applesauce, jarred 0.02
Chocolate candy Bananas 0.06
Chocolate candy Cantaloupe -0.14
Chocolate candy Fruit cocktail, canned -0.07
Chocolate candy Grapes -0.08

Cleaning up the names - by removing punctuations and special characters for better visualization

df1$Snacks <-
  str_trim(
    ifelse(is.na(str_locate(df1$Snacks,"\\(")[,"start"]), df1$Snacks,str_sub(df1$Snacks, 1, str_locate(df1$Snacks,"\\(")[,"start"] - 1)
    )
  )

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

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

Joining Both data set

df3 <- inner_join(df1,df2)
## Joining, by = c("Snacks", "Healthy_items")
df3 %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Snacks Healthy_items Calorie Cost
Chocolate candy Apples 185 -0.12
Chocolate candy Bananas 160 0.06
Chocolate candy Cantaloupe 229 -0.14
Chocolate candy Grapes 203 -0.08
Chocolate candy Oranges 209 0.04
Chocolate candy Plums 224 -0.01
Chocolate candy Raisins 153 0.05
Chocolate candy Strawberries 235 -0.17
Chocolate candy Tangerine 190 -0.27
Chocolate candy Watermelon 188 -0.01
Chocolate candy Broccoli 250 0.06
Chocolate candy Carrots 240 0.05
Chocolate candy Celery 252 0.08
Cookies Apples 46 -0.20
Cookies Bananas 21 -0.02
Cookies Cantaloupe 90 -0.22
Cookies Grapes 64 -0.16
Cookies Oranges 70 -0.04
Cookies Plums 85 -0.09
Cookies Raisins 14 -0.03
Cookies Strawberries 96 -0.25
Cookies Tangerine 51 -0.35
Cookies Watermelon 49 -0.09
Cookies Broccoli 111 -0.02
Cookies Carrots 101 -0.03
Cookies Celery 113 0.00
Corn chips Apples 63 -0.15
Corn chips Bananas 38 0.03
Corn chips Cantaloupe 107 -0.17
Corn chips Grapes 81 -0.11
Corn chips Oranges 87 0.01
Corn chips Plums 102 -0.04
Corn chips Raisins 31 0.02
Corn chips Strawberries 113 -0.20
Corn chips Tangerine 68 -0.30
Corn chips Watermelon 66 -0.04
Corn chips Broccoli 128 0.03
Corn chips Carrots 118 0.02
Corn chips Celery 130 0.05
Crackers Apples 37 -0.20
Crackers Bananas 12 -0.02
Crackers Cantaloupe 81 -0.22
Crackers Grapes 55 -0.16
Crackers Oranges 61 -0.04
Crackers Plums 76 -0.09
Crackers Raisins 5 -0.03
Crackers Strawberries 87 -0.25
Crackers Tangerine 42 -0.35
Crackers Watermelon 40 -0.09
Crackers Broccoli 102 -0.02
Crackers Carrots 92 -0.03
Crackers Celery 104 0.00
Cupcakes Apples 97 -0.02
Cupcakes Bananas 72 0.16
Cupcakes Cantaloupe 141 -0.04
Cupcakes Grapes 115 0.02
Cupcakes Oranges 121 0.14
Cupcakes Plums 136 0.09
Cupcakes Raisins 65 0.15
Cupcakes Strawberries 147 -0.07
Cupcakes Tangerine 102 -0.17
Cupcakes Watermelon 100 0.09
Cupcakes Broccoli 162 0.16
Cupcakes Carrots 152 0.15
Cupcakes Celery 164 0.18
Danish Apples 194 0.11
Danish Bananas 169 0.29
Danish Cantaloupe 238 0.09
Danish Grapes 212 0.15
Danish Oranges 218 0.27
Danish Plums 233 0.22
Danish Raisins 162 0.28
Danish Strawberries 244 0.06
Danish Tangerine 199 -0.04
Danish Watermelon 197 0.22
Danish Broccoli 259 0.29
Danish Carrots 249 0.28
Danish Celery 261 0.31
Donuts Apples 158 0.00
Donuts Bananas 133 0.18
Donuts Cantaloupe 202 -0.02
Donuts Grapes 176 0.04
Donuts Oranges 182 0.16
Donuts Plums 197 0.11
Donuts Raisins 126 0.17
Donuts Strawberries 208 -0.05
Donuts Tangerine 163 -0.15
Donuts Watermelon 161 0.11
Donuts Broccoli 223 0.18
Donuts Carrots 213 0.17
Donuts Celery 225 0.20
Fruit rolls Apples 5 -0.08
Fruit rolls Bananas -20 0.10
Fruit rolls Cantaloupe 49 -0.10
Fruit rolls Grapes 23 -0.04
Fruit rolls Oranges 29 0.08
Fruit rolls Plums 44 0.03
Fruit rolls Raisins -27 0.09
Fruit rolls Strawberries 55 -0.13
Fruit rolls Tangerine 10 -0.23
Fruit rolls Watermelon 8 0.03
Fruit rolls Broccoli 70 0.10
Fruit rolls Carrots 60 0.09
Fruit rolls Celery 72 0.12
Graham crackers Apples 25 -0.22
Graham crackers Bananas 0 -0.04
Graham crackers Cantaloupe 69 -0.24
Graham crackers Grapes 43 -0.18
Graham crackers Oranges 49 -0.06
Graham crackers Plums 64 -0.11
Graham crackers Raisins -7 -0.05
Graham crackers Strawberries 75 -0.27
Graham crackers Tangerine 30 -0.37
Graham crackers Watermelon 28 -0.11
Graham crackers Broccoli 90 -0.04
Graham crackers Carrots 80 -0.05
Graham crackers Celery 92 -0.02
Granola bars Apples 42 -0.06
Granola bars Bananas 17 0.12
Granola bars Cantaloupe 86 -0.08
Granola bars Grapes 60 -0.02
Granola bars Oranges 66 0.10
Granola bars Plums 81 0.05
Granola bars Raisins 10 0.11
Granola bars Strawberries 92 -0.11
Granola bars Tangerine 47 -0.21
Granola bars Watermelon 45 0.05
Granola bars Broccoli 107 0.12
Granola bars Carrots 97 0.11
Granola bars Celery 109 0.14
Ice cream Apples 119 0.03
Ice cream Bananas 94 0.21
Ice cream Cantaloupe 163 0.01
Ice cream Grapes 137 0.07
Ice cream Oranges 143 0.19
Ice cream Plums 158 0.14
Ice cream Raisins 87 0.20
Ice cream Strawberries 169 -0.02
Ice cream Tangerine 124 -0.12
Ice cream Watermelon 122 0.14
Ice cream Broccoli 184 0.21
Ice cream Carrots 174 0.20
Ice cream Celery 186 0.23
Muffins Apples 292 0.47
Muffins Bananas 267 0.65
Muffins Cantaloupe 336 0.45
Muffins Grapes 310 0.51
Muffins Oranges 316 0.63
Muffins Plums 331 0.58
Muffins Raisins 260 0.64
Muffins Strawberries 342 0.42
Muffins Tangerine 297 0.32
Muffins Watermelon 295 0.58
Muffins Broccoli 357 0.65
Muffins Carrots 347 0.64
Muffins Celery 359 0.67
Pizza, from frozen Apples 175 0.27
Pizza, from frozen Bananas 150 0.45
Pizza, from frozen Cantaloupe 219 0.25
Pizza, from frozen Grapes 193 0.31
Pizza, from frozen Oranges 199 0.43
Pizza, from frozen Plums 214 0.38
Pizza, from frozen Raisins 143 0.44
Pizza, from frozen Strawberries 225 0.22
Pizza, from frozen Tangerine 180 0.12
Pizza, from frozen Watermelon 178 0.38
Pizza, from frozen Broccoli 240 0.45
Pizza, from frozen Carrots 230 0.44
Pizza, from frozen Celery 242 0.47
Popsicles and bars Apples 3 -0.02
Popsicles and bars Bananas -22 0.16
Popsicles and bars Cantaloupe 47 -0.04
Popsicles and bars Grapes 21 0.02
Popsicles and bars Oranges 27 0.14
Popsicles and bars Plums 42 0.09
Popsicles and bars Raisins -29 0.15
Popsicles and bars Strawberries 53 -0.07
Popsicles and bars Tangerine 8 -0.17
Popsicles and bars Watermelon 6 0.09
Popsicles and bars Broccoli 68 0.16
Popsicles and bars Carrots 58 0.15
Popsicles and bars Celery 70 0.18
Potato chips Apples 92 -0.09
Potato chips Bananas 67 0.09
Potato chips Cantaloupe 136 -0.11
Potato chips Grapes 110 -0.05
Potato chips Oranges 116 0.07
Potato chips Plums 131 0.02
Potato chips Raisins 60 0.08
Potato chips Strawberries 142 -0.14
Potato chips Tangerine 97 -0.24
Potato chips Watermelon 95 0.02
Potato chips Broccoli 157 0.09
Potato chips Carrots 147 0.08
Potato chips Celery 159 0.11
Pretzels Apples 91 -0.11
Pretzels Bananas 66 0.07
Pretzels Cantaloupe 135 -0.13
Pretzels Grapes 109 -0.07
Pretzels Oranges 115 0.05
Pretzels Plums 130 0.00
Pretzels Raisins 59 0.06
Pretzels Strawberries 141 -0.16
Pretzels Tangerine 96 -0.26
Pretzels Watermelon 94 0.00
Pretzels Broccoli 156 0.07
Pretzels Carrots 146 0.06
Pretzels Celery 158 0.09
Pudding, ready-to-eat Apples 75 0.02
Pudding, ready-to-eat Bananas 50 0.20
Pudding, ready-to-eat Cantaloupe 119 0.00
Pudding, ready-to-eat Grapes 93 0.06
Pudding, ready-to-eat Oranges 99 0.18
Pudding, ready-to-eat Plums 114 0.13
Pudding, ready-to-eat Raisins 43 0.19
Pudding, ready-to-eat Strawberries 125 -0.03
Pudding, ready-to-eat Tangerine 80 -0.13
Pudding, ready-to-eat Watermelon 78 0.13
Pudding, ready-to-eat Broccoli 140 0.20
Pudding, ready-to-eat Carrots 130 0.19
Pudding, ready-to-eat Celery 142 0.22
Sandwich crackers Apples 106 -0.16
Sandwich crackers Bananas 81 0.02
Sandwich crackers Cantaloupe 150 -0.18
Sandwich crackers Grapes 124 -0.12
Sandwich crackers Oranges 130 0.00
Sandwich crackers Plums 145 -0.05
Sandwich crackers Raisins 74 0.01
Sandwich crackers Strawberries 156 -0.21
Sandwich crackers Tangerine 111 -0.31
Sandwich crackers Watermelon 109 -0.05
Sandwich crackers Broccoli 171 0.02
Sandwich crackers Carrots 161 0.01
Sandwich crackers Celery 173 0.04
Toaster pastries Apples 222 -0.01
Toaster pastries Bananas 197 0.17
Toaster pastries Cantaloupe 266 -0.03
Toaster pastries Grapes 240 0.03
Toaster pastries Oranges 246 0.15
Toaster pastries Plums 261 0.10
Toaster pastries Raisins 190 0.16
Toaster pastries Strawberries 272 -0.06
Toaster pastries Tangerine 227 -0.16
Toaster pastries Watermelon 225 0.10
Toaster pastries Broccoli 287 0.17
Toaster pastries Carrots 277 0.16
Toaster pastries Celery 289 0.19
Tortilla chips Apples 84 -0.15
Tortilla chips Bananas 59 0.03
Tortilla chips Cantaloupe 128 -0.17
Tortilla chips Grapes 102 -0.11
Tortilla chips Oranges 108 0.01
Tortilla chips Plums 123 -0.04
Tortilla chips Raisins 52 0.02
Tortilla chips Strawberries 134 -0.20
Tortilla chips Tangerine 89 -0.30
Tortilla chips Watermelon 87 -0.04
Tortilla chips Broccoli 149 0.03
Tortilla chips Carrots 139 0.02
Tortilla chips Celery 151 0.05

Data Visualization

Bar plot with google docs theme for Healthy snacks based on average calorie impact

Here top Healthy snacks which can be replaced in place of Snacks based on Calorie

ggplot(df3, aes(x = reorder(Healthy_items,Calorie), y = Calorie)) + 
  geom_bar(stat = "identity", position = "dodge", fill = "black")  +
  scale_fill_brewer(palette="Paired") + 
  theme_gdocs() + scale_color_gdocs()+ 
  theme(plot.title = element_text(hjust = 0.5)) +
  ggtitle("Top Healthy Snack based on Average Calorie Impact") +
  xlab("Healthy Snack Alternative") +  ylab ("Average Calorie") +
  coord_flip()

Bar plot of Healthy Items with above and below 100 calorie

Below graph displays the top healthy item alternative based on Calorie

df3$Total_Calorie = ifelse(df3$Calorie >= 100, "above", "below")

ggplot(df3, aes(x = reorder(Healthy_items,Calorie), y = Calorie)) +
  geom_bar(stat = "identity", position = "dodge",aes(fill = Total_Calorie)) +
  scale_fill_manual(name="Calorie Impact", 
                    labels = c("Less Calorie Substitue", "More Calorie Substitute"), 
                    values = c("above"="red", "below"="yellow")) + 
  ggtitle("Top Healthy items based on Calorie Impact") +
  theme(plot.title = element_text(hjust = 0.5),legend.position = "bottom") +
  xlab("Healthy Items") +  ylab ("Total Calorie Impact") +
  coord_flip()

Histogram on a Calorie count over Healthy Items

Here Histogram is plotted against the Calorie count and Vegetable and Fruits as the frequency

g <- ggplot(df3, aes(Calorie)) + scale_fill_brewer(palette = "Spectral")

g + geom_histogram(aes(fill=Healthy_items), 
                   binwidth = 5, 
                   col="black", 
                   size=.1) +  # change binwidth
  labs(title="Calorie count over Healthy Items", 
       subtitle="Calorie count over Healthy Items")  
## Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Spectral is 11
## Returning the palette you asked for with that many colors

Histogram on a Calorie count over Snacks Items

Here Histogram is plotted against the Calorie count and snacks as the frequency

g + geom_histogram(aes(fill=Snacks), 
                   bins=5, 
                   col="black", 
                   size=.1) +   # change number of bins
  labs(title="Calorie count Snacks alternative", 
       subtitle="Calorie count over Snacks Items") 
## Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Spectral is 11
## Returning the palette you asked for with that many colors

library(ggplot2)
theme_set(theme_classic())

Density Plot of snacks over calorie

Here Density plot is plotted against the Snacks as a class and Calorie as count

g <- ggplot(df3, aes(Calorie))
g + geom_density(aes(fill=factor(Snacks)), alpha=0.8) + 
  labs(title="Density plot", 
       subtitle="Snacks Over Calorie",
       caption="Source: Snacks Over Calorie density",
       x="Calorie",
       fill="Snacks")

Density Plot of Healthy items over calorie

Here Density plot is plotted against the Healthy Veg and Fruits as a class and Calorie as count

g <- ggplot(df3, aes(Calorie))
g + geom_density(aes(fill=factor(Healthy_items)), alpha=0.8) + 
  labs(title="Density plot", 
       subtitle="Healthy Veg and Fruits Over Calorie",
       caption="Source: Healthy Veg and Fruits Over Calorie density",
       x="Calorie",
       fill=" Healthy_items")

Box Plot of Healthy items over Calorie

Here box plot is plotted against the Healthy Veg and Fruits and Calorie

g <- ggplot(df3, aes(Calorie, Healthy_items))
g + geom_boxplot(varwidth=T, fill="maroon") + 
  labs(title="Box plot", 
       subtitle="Healthy Veg and Fruits Over Calorie box plot",
       caption="Source: Healthy Veg and Fruits against Calorie",
       x="Veg and Fruits",
       y="Calorie")

Box Plot of Snacks items over Calorie

Here box plot is plotted against the Snacks and Calorie

g <- ggplot(df3, aes(Calorie, Snacks))
g + geom_boxplot(varwidth=T, fill="purple") + 
  labs(title="Box plot", 
       subtitle="Healthy Veg and Fruits Over Calorie box plot",
       caption="Source: Snacks against Calorie",
       x="Calorie",
       y="Snacks")

Scatter Plot of Healthy Vegetable & Fruits over Calorie

Scatter plot represent two different numeric plots in the form of dots. Here cost is plotted against the Calorie to get an idea of Healthy vegetable and Fruits - Cost and Calorie

scatter <- ggplot(data = df3) +   
  geom_point(mapping = aes(x = `Calorie`, y = `Cost`, color = `Healthy_items`))+
  scale_x_discrete(guide = guide_axis(n.dodge=3))
print(scatter + ggtitle("Healthy items over calorie  "))

Scatter Plot of Snacks items over Calorie

Scatter plot represent two different numeric plots in the form of dots. Here cost is plotted against the Calorie to get an idea of Snacks - Cost and Calorie

scatter <- ggplot(data = df3) +   
  geom_point(mapping = aes(x = `Calorie`, y = `Cost`, color = `Snacks`))+
  scale_x_discrete(guide = guide_axis(n.dodge=3))
print(scatter + ggtitle("Healthy items over calorie  "))

Bar plot of Healthy Items with above and below 0 cost

Below graph displays the top healthy item alternative based on Cost

df3$Total_Cost = ifelse(df3$Cost >= 0, "above", "below")

ggplot(df3, aes(x = reorder(Healthy_items,Cost), y = Cost)) +
  geom_bar(stat = "identity", position = "dodge",aes(fill = Total_Cost)) +
  scale_fill_manual(name="Cost Impact", 
                    labels = c("Less Costly alternative", "More Costly alternative"), 
                    values = c("above"="green", "below"="orange")) + 
  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()