Thanksgiving is just around the corner. Let’s celebrate the best way we know how, by analyzing some festive data! I hope you have fun making graphics! Happy Thanksgiving!
We are using the data from fivethirtyeight the Here’s What Your Part of America Eats on Thanksgiving article https://fivethirtyeight.com/features/heres-what-your-part-of-america-eats-on-thanksgiving/.
The original data set can be found here: https://raw.githubusercontent.com/fivethirtyeight/data/master/thanksgiving-2015/thanksgiving-2015-poll-data.csv
The variables for the survey are described here:https://github.com/fivethirtyeight/data/tree/master/thanksgiving-2015
I cleaned up the data, selected a subset of variables, and created binary variables. My dataset can be found here: https://raw.githubusercontent.com/kitadasmalley/FA2020_DataViz/main/data/useThanks.csv
useThanks<-read.csv("https://raw.githubusercontent.com/kitadasmalley/FA2020_DataViz/main/data/useThanks.csv",
header=TRUE)
str(useThanks)
## 'data.frame': 1058 obs. of 83 variables:
## $ id : num 4.34e+09 4.34e+09 4.34e+09 4.34e+09 4.34e+09 ...
## $ celebrate : Factor w/ 2 levels "No","Yes": 2 2 2 2 2 2 2 2 2 2 ...
## $ main : Factor w/ 9 levels "","Chicken","Ham/Pork",..: 9 9 9 9 7 9 9 9 9 5 ...
## $ cooked : Factor w/ 6 levels "","Baked","Fried",..: 2 2 6 2 2 6 2 2 6 2 ...
## $ stuffing : Factor w/ 5 levels "","Bread-based",..: 2 2 5 2 2 5 2 5 2 2 ...
## $ cranberry : Factor w/ 5 levels "","Canned","Homemade",..: 4 5 3 3 2 3 2 3 2 5 ...
## $ gravy : Factor w/ 3 levels "","No","Yes": 3 3 3 3 3 3 3 3 3 3 ...
## $ brussel.sprouts : Factor w/ 2 levels "","Brussel sprouts": 1 1 2 2 2 2 1 1 2 2 ...
## $ carrots : Factor w/ 2 levels "","Carrots": 2 1 2 1 1 2 1 2 1 2 ...
## $ cauliflower : Factor w/ 2 levels "","Cauliflower": 1 1 2 1 1 2 1 1 1 1 ...
## $ corn : Factor w/ 2 levels "","Corn": 1 2 2 1 1 2 1 1 2 1 ...
## $ cornbread : Factor w/ 2 levels "","Cornbread": 1 1 2 2 2 2 1 1 2 1 ...
## $ fruit.salad : Factor w/ 2 levels "","Fruit salad": 1 1 1 1 1 2 2 1 1 1 ...
## $ green.beans : Factor w/ 2 levels "","Green beans/green bean casserole": 2 2 1 1 1 2 2 1 2 2 ...
## $ mac.n.cheese : Factor w/ 2 levels "","Macaroni and cheese": 2 2 1 1 1 2 1 1 1 1 ...
## $ mashed.potatoes : Factor w/ 2 levels "","Mashed potatoes": 2 2 2 2 2 2 2 1 2 2 ...
## $ rolls : Factor w/ 2 levels "","Rolls/biscuits": 1 2 2 2 2 2 2 1 2 2 ...
## $ squash : Factor w/ 2 levels "","Squash": 1 1 1 1 2 2 1 1 2 1 ...
## $ salad : Factor w/ 2 levels "","Vegetable salad": 1 2 2 2 2 2 1 1 1 1 ...
## $ yams.sweet.potato : Factor w/ 2 levels "","Yams/sweet potato casserole": 2 2 1 2 2 2 2 1 1 2 ...
## $ apple.pie : Factor w/ 2 levels "","Apple": 2 2 2 1 2 1 2 1 2 1 ...
## $ buttermilk.pie : Factor w/ 2 levels "","Buttermilk": 1 1 1 1 1 1 1 1 2 2 ...
## $ cherry.pie : Factor w/ 2 levels "","Cherry": 1 1 2 1 1 1 1 1 1 1 ...
## $ chocolate.pie : Factor w/ 2 levels "","Chocolate": 1 2 1 1 1 1 1 2 1 1 ...
## $ coconut.pie : Factor w/ 2 levels "","Coconut cream": 1 1 1 1 1 1 1 1 1 1 ...
## $ keylime.pie : Factor w/ 2 levels "","Key lime": 1 1 1 1 1 1 1 1 1 1 ...
## $ peach.pie : Factor w/ 2 levels "","Peach": 1 1 2 1 1 1 1 1 1 1 ...
## $ pecan.pie : Factor w/ 2 levels "","Pecan": 1 1 2 2 1 1 1 1 1 1 ...
## $ pumpkin.pie : Factor w/ 2 levels "","Pumpkin": 1 2 2 2 2 1 2 1 2 2 ...
## $ sweet.potato.pie : Factor w/ 2 levels "","Sweet Potato": 1 1 2 1 1 2 1 1 2 2 ...
## $ apple.cobbler : Factor w/ 2 levels "","Apple cobbler": 1 1 1 1 1 1 1 1 1 1 ...
## $ blondies : Factor w/ 2 levels "","Blondies": 1 1 1 1 1 1 1 1 1 1 ...
## $ brownies : Factor w/ 2 levels "","Brownies": 1 1 2 1 1 1 1 1 1 1 ...
## $ carrot.cake : Factor w/ 2 levels "","Carrot cake": 1 1 2 1 1 1 1 1 1 1 ...
## $ cheesecake : Factor w/ 2 levels "","Cheesecake": 2 2 1 1 1 2 1 1 1 1 ...
## $ cookies : Factor w/ 2 levels "","Cookies": 2 2 2 1 1 1 2 2 2 1 ...
## $ fudge : Factor w/ 2 levels "","Fudge": 1 1 2 1 1 1 1 1 1 1 ...
## $ ice.cream : Factor w/ 2 levels "","Ice cream": 2 1 2 1 1 1 1 1 1 1 ...
## $ peach.cobbler : Factor w/ 2 levels "","Peach cobbler": 1 1 1 1 1 1 1 1 1 1 ...
## $ pray : Factor w/ 3 levels "","No","Yes": 3 3 3 2 2 3 2 2 2 3 ...
## $ friendsgiving : Factor w/ 3 levels "","No","Yes": 2 2 3 2 2 3 2 3 2 2 ...
## $ black.friday : Factor w/ 3 levels "","No","Yes": 2 3 3 2 2 3 3 3 2 2 ...
## $ area.live : Factor w/ 4 levels "","Rural","Suburban",..: 3 2 3 4 4 4 2 2 4 3 ...
## $ age : Factor w/ 5 levels "","18 - 29","30 - 44",..: 2 2 2 3 3 2 2 2 3 3 ...
## $ gender : Factor w/ 3 levels "","Female","Male": 3 2 3 3 3 3 3 3 3 3 ...
## $ income : Factor w/ 12 levels "","$0 to $9,999",..: 11 10 2 8 4 2 9 12 11 9 ...
## $ DivName : Factor w/ 10 levels "","East North Central",..: 4 3 5 7 7 7 2 5 4 3 ...
## $ celebrate01 : int 1 1 1 1 1 1 1 1 1 1 ...
## $ gravy01 : int 1 1 1 1 1 1 1 1 1 1 ...
## $ friendsgiving01 : int 0 0 1 0 0 1 0 1 0 0 ...
## $ black.friday01 : int 0 1 1 0 0 1 1 1 0 0 ...
## $ brussel.sprouts01 : int 0 0 1 1 1 1 0 0 1 1 ...
## $ carrots01 : int 1 0 1 0 0 1 0 1 0 1 ...
## $ cauliflower01 : int 0 0 1 0 0 1 0 0 0 0 ...
## $ corn01 : int 0 1 1 0 0 1 0 0 1 0 ...
## $ cornbread01 : int 0 0 1 1 1 1 0 0 1 0 ...
## $ fruit.salad01 : int 0 0 0 0 0 1 1 0 0 0 ...
## $ green.beans01 : int 1 1 0 0 0 1 1 0 1 1 ...
## $ mac.n.cheese01 : int 1 1 0 0 0 1 0 0 0 0 ...
## $ mashed.potatoes01 : int 1 1 1 1 1 1 1 0 1 1 ...
## $ rolls01 : int 0 1 1 1 1 1 1 0 1 1 ...
## $ squash01 : int 0 0 0 0 1 1 0 0 1 0 ...
## $ salad01 : int 0 1 1 1 1 1 0 0 0 0 ...
## $ yams.sweet.potato01: int 1 1 0 1 1 1 1 0 0 1 ...
## $ apple.pie01 : int 1 1 1 0 1 0 1 0 1 0 ...
## $ buttermilk.pie01 : int 0 0 0 0 0 0 0 0 1 1 ...
## $ cherry.pie01 : int 0 0 1 0 0 0 0 0 0 0 ...
## $ chocolate.pie01 : int 0 1 0 0 0 0 0 1 0 0 ...
## $ coconut.pie01 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ keylime.pie01 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ peach.pie01 : int 0 0 1 0 0 0 0 0 0 0 ...
## $ pecan.pie01 : int 0 0 1 1 0 0 0 0 0 0 ...
## $ pumpkin.pie01 : int 0 1 1 1 1 0 1 0 1 1 ...
## $ sweet.potato.pie01 : int 0 0 1 0 0 1 0 0 1 1 ...
## $ apple.cobbler01 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ blondies01 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ brownies01 : int 0 0 1 0 0 0 0 0 0 0 ...
## $ carrot.cake01 : int 0 0 1 0 0 0 0 0 0 0 ...
## $ cheesecake01 : int 1 1 0 0 0 1 0 0 0 0 ...
## $ cookies01 : int 1 1 1 0 0 0 1 1 1 0 ...
## $ fudge01 : int 0 0 1 0 0 0 0 0 0 0 ...
## $ ice.cream01 : int 1 0 1 0 0 0 0 0 0 0 ...
## $ peach.cobbler01 : int 0 0 0 0 0 0 0 0 0 0 ...
This is pretty tough and requires a fair bit of data wrangling. Here are a few hints to help you along the way.
library(tidyverse)
divPie<-useThanks%>%
group_by(DivName)%>%
summarise(appleTot=sum(apple.pie01, na.rm=TRUE),
buttermilkTot=sum(buttermilk.pie01, na.rm=TRUE),
cherryTot=sum(cherry.pie01, na.rm=TRUE),
chocoTot=sum(chocolate.pie01, na.rm=TRUE),
cocoTot=sum(coconut.pie01, na.rm=TRUE),
keylimeTot=sum(keylime.pie01, na.rm=TRUE),
peachTot=sum(peach.pie01, na.rm=TRUE),
pecanTot=sum(pecan.pie01, na.rm=TRUE),
pumpkinTot=sum(pumpkin.pie01, na.rm=TRUE),
sweetpoTot=sum(sweet.potato.pie01, na.rm=TRUE),
brusselTot=sum(brussel.sprouts01, na.rm=TRUE),
carrotsTot=sum(carrots01, na.rm=TRUE),
cauliflTot=sum(cauliflower01, na.rm=TRUE),
cornTot=sum(corn01, na.rm=TRUE),
cornbreadTot=sum(cornbread01, na.rm=TRUE),
fruitsalTot=sum(fruit.salad01, na.rm=TRUE),
greenbTot=sum(green.beans01, na.rm=TRUE),
macncheeTot=sum(mac.n.cheese01, na.rm=TRUE),
mashedTot=sum(mashed.potatoes01, na.rm=TRUE),
rollsTot=sum(rolls01, na.rm=TRUE),
squashTot=sum(squash01, na.rm=TRUE),
saladTot=sum(salad01, na.rm=TRUE),
yamsTot=sum(yams.sweet.potato01, na.rm=TRUE),
n=n())
head(divPie)
## # A tibble: 6 x 25
## DivName appleTot buttermilkTot cherryTot chocoTot cocoTot keylimeTot peachTot
## <fct> <int> <int> <int> <int> <int> <int> <int>
## 1 "" 10 2 5 6 2 1 1
## 2 "East … 75 3 22 11 2 3 3
## 3 "East … 19 6 4 9 2 1 4
## 4 "Middl… 106 2 17 16 9 1 4
## 5 "Mount… 19 0 7 2 0 1 2
## 6 "New E… 41 1 0 12 4 2 2
## # … with 17 more variables: pecanTot <int>, pumpkinTot <int>, sweetpoTot <int>,
## # brusselTot <int>, carrotsTot <int>, cauliflTot <int>, cornTot <int>,
## # cornbreadTot <int>, fruitsalTot <int>, greenbTot <int>, macncheeTot <int>,
## # mashedTot <int>, rollsTot <int>, squashTot <int>, saladTot <int>,
## # yamsTot <int>, n <int>
divPie<-divPie%>%
mutate(appleProp=appleTot/n,
buttermilkProp=buttermilkTot/n,
cherryProp=cherryTot/n,
chocoProp=chocoTot/n,
cocoProp=cocoTot/n,
keylimeProp=keylimeTot/n,
peachProp=peachTot/n,
pecanProp=pecanTot/n,
pumpkinProp=pumpkinTot/n,
sweetpoProp=sweetpoTot/n,
brusselProp=brusselTot/n,
carrotsProp=carrotsTot/n,
cauliflProp=cauliflTot/n,
cornProp=cornTot/n,
cornbreadProp=cornbreadTot/n,
fruitsalProp=fruitsalTot/n,
greenbProp=greenbTot/n,
macncheeProp=macncheeTot/n,
mashedProp=mashedTot/n,
rollsProp=rollsTot/n,
squashProp=squashTot/n,
saladProp=saladTot/n,
yamsProp=yamsTot/n)
head(divPie)
## # A tibble: 6 x 48
## DivName appleTot buttermilkTot cherryTot chocoTot cocoTot keylimeTot peachTot
## <fct> <int> <int> <int> <int> <int> <int> <int>
## 1 "" 10 2 5 6 2 1 1
## 2 "East … 75 3 22 11 2 3 3
## 3 "East … 19 6 4 9 2 1 4
## 4 "Middl… 106 2 17 16 9 1 4
## 5 "Mount… 19 0 7 2 0 1 2
## 6 "New E… 41 1 0 12 4 2 2
## # … with 40 more variables: pecanTot <int>, pumpkinTot <int>, sweetpoTot <int>,
## # brusselTot <int>, carrotsTot <int>, cauliflTot <int>, cornTot <int>,
## # cornbreadTot <int>, fruitsalTot <int>, greenbTot <int>, macncheeTot <int>,
## # mashedTot <int>, rollsTot <int>, squashTot <int>, saladTot <int>,
## # yamsTot <int>, n <int>, appleProp <dbl>, buttermilkProp <dbl>,
## # cherryProp <dbl>, chocoProp <dbl>, cocoProp <dbl>, keylimeProp <dbl>,
## # peachProp <dbl>, pecanProp <dbl>, pumpkinProp <dbl>, sweetpoProp <dbl>,
## # brusselProp <dbl>, carrotsProp <dbl>, cauliflProp <dbl>, cornProp <dbl>,
## # cornbreadProp <dbl>, fruitsalProp <dbl>, greenbProp <dbl>,
## # macncheeProp <dbl>, mashedProp <dbl>, rollsProp <dbl>, squashProp <dbl>,
## # saladProp <dbl>, yamsProp <dbl>
In order to assess what dishes are served “disproportionately” by region, we first need to understand national trends. Thus, we must calculate national values as weighted averages by population distribution in regions. This data comes from https://www.hcup-us.ahrq.gov/figures/nis_figure1_2018.jsp
Here is some data about how people are distributed accross regions:
popDiv<-data.frame(DivName=c("East North Central",
"East South Central",
"Middle Atlantic",
"Mountain",
"New England",
"Pacific",
"South Atlantic",
"West North Central",
"West South Central"),
pop=c(46798649,
18931477,
41601787,
23811346,
14757573,
52833604,
63991523,
21179519,
39500457))%>%
mutate(popProp=pop/323405935)
popDiv
## DivName pop popProp
## 1 East North Central 46798649 0.14470560
## 2 East South Central 18931477 0.05853782
## 3 Middle Atlantic 41601787 0.12863644
## 4 Mountain 23811346 0.07362681
## 5 New England 14757573 0.04563173
## 6 Pacific 52833604 0.16336622
## 7 South Atlantic 63991523 0.19786750
## 8 West North Central 21179519 0.06548896
## 9 West South Central 39500457 0.12213894
natPie2<-divPie%>%
left_join(popDiv)%>%
mutate(applePropW=appleProp*popProp,
buttermilkPropW=buttermilkProp*popProp,
cherryPropW=cherryProp*popProp,
chocoPropW=chocoProp*popProp,
cocoPropW=cocoProp*popProp,
keylimePropW=keylimeProp*popProp,
peachPropW=peachProp*popProp,
pecanPropW=pecanProp*popProp,
pumpkinPropW=pumpkinProp*popProp,
sweetpoPropW=sweetpoProp*popProp,
brusselPropW=brusselProp*popProp,
carrotsPropW=carrotsProp*popProp,
cauliflPropW=cauliflProp*popProp,
cornPropW=cornProp*popProp,
cornbreadPropW=cornbreadProp*popProp,
fruitsalPropW=fruitsalProp*popProp,
greenbPropW=greenbProp*popProp,
macncheePropW=macncheeProp*popProp,
mashedPropW=mashedProp*popProp,
rollsPropW=rollsProp*popProp,
squashPropW=squashProp*popProp,
saladPropW=saladProp*popProp,
yamsPropW=yamsProp*popProp)%>%
summarise(nappleProp2=sum(applePropW, na.rm=TRUE),
nbuttermilkProp2=sum(buttermilkPropW, na.rm=TRUE),
ncherryProp2=sum(cherryPropW, na.rm=TRUE),
nchocoProp2=sum(chocoPropW, na.rm=TRUE),
ncocoProp2=sum(cocoPropW, na.rm=TRUE),
nkeylimeProp2=sum(keylimePropW, na.rm=TRUE),
npeachProp2=sum(peachPropW, na.rm=TRUE),
npecanProp2=sum(pecanPropW, na.rm=TRUE),
npumpkinProp2=sum(pumpkinPropW, na.rm=TRUE),
nsweetpoProp2=sum(sweetpoPropW, na.rm=TRUE),
nbrusselProp2=sum(brusselPropW, na.rm=TRUE),
ncarrotsProp2=sum(carrotsPropW, na.rm=TRUE),
ncauliflProp2=sum(cauliflPropW, na.rm=TRUE),
ncornProp2=sum(cornPropW, na.rm=TRUE),
ncornbreadProp2=sum(cornbreadPropW, na.rm=TRUE),
nfruitsalProp2=sum(fruitsalPropW, na.rm=TRUE),
ngreenbProp2=sum(greenbPropW, na.rm=TRUE),
nmacncheeProp2=sum(macncheePropW, na.rm=TRUE),
nmashedProp2=sum(mashedPropW, na.rm=TRUE),
nrollsProp2=sum(rollsPropW, na.rm=TRUE),
nsquashProp2=sum(squashPropW, na.rm=TRUE),
nsaladProp2=sum(saladPropW, na.rm=TRUE),
nyamsProp2=sum(yamsPropW, na.rm=TRUE))
## Joining, by = "DivName"
head(natPie2)
## # A tibble: 1 x 23
## nappleProp2 nbuttermilkProp2 ncherryProp2 nchocoProp2 ncocoProp2 nkeylimeProp2
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0.491 0.0363 0.111 0.126 0.0331 0.0389
## # … with 17 more variables: npeachProp2 <dbl>, npecanProp2 <dbl>,
## # npumpkinProp2 <dbl>, nsweetpoProp2 <dbl>, nbrusselProp2 <dbl>,
## # ncarrotsProp2 <dbl>, ncauliflProp2 <dbl>, ncornProp2 <dbl>,
## # ncornbreadProp2 <dbl>, nfruitsalProp2 <dbl>, ngreenbProp2 <dbl>,
## # nmacncheeProp2 <dbl>, nmashedProp2 <dbl>, nrollsProp2 <dbl>,
## # nsquashProp2 <dbl>, nsaladProp2 <dbl>, nyamsProp2 <dbl>
divPie2<-divPie%>%
mutate(appleDiff2=appleProp-natPie2$nappleProp2,
buttermilkDiff2=buttermilkProp-natPie2$nbuttermilkProp2,
cherryDiff2=cherryProp-natPie2$ncherryProp2,
chocoDiff2=chocoProp-natPie2$nchocoProp2,
cocoDiff2=cocoProp-natPie2$ncocoProp2,
keylimeDiff2=keylimeProp-natPie2$nkeylimeProp2,
peachDiff2=peachProp-natPie2$npeachProp2,
pecanDiff2=pecanProp-natPie2$npecanProp2,
pumpkinDiff2=pumpkinProp-natPie2$npumpkinProp2,
sweetpoDiff2=sweetpoProp-natPie2$nsweetpoProp2,
brusselDiff2=brusselProp-natPie2$nbrusselProp2,
carrotsDiff2=carrotsProp-natPie2$ncarrotsProp2,
cauliflDiff2=cauliflProp-natPie2$ncauliflProp2,
cornDiff2=cornProp-natPie2$ncornProp2,
cornbreadDiff2=cornbreadProp-natPie2$ncornbreadProp2,
fruitsalDiff2=fruitsalProp-natPie2$nfruitsalProp2,
greenbDiff2=greenbProp-natPie2$ngreenbProp2,
macncheeDiff2=macncheeProp-natPie2$nmacncheeProp2,
mashedDiff2=mashedProp-natPie2$nmashedProp2,
rollsDiff2=rollsProp-natPie2$nrollsProp2,
squashDiff2=squashProp-natPie2$nsquashProp2,
saladDiff2=saladProp-natPie2$nsaladProp2,
yamsDiff2=yamsProp-natPie2$nyamsProp2)
head(divPie2)
## # A tibble: 6 x 71
## DivName appleTot buttermilkTot cherryTot chocoTot cocoTot keylimeTot peachTot
## <fct> <int> <int> <int> <int> <int> <int> <int>
## 1 "" 10 2 5 6 2 1 1
## 2 "East … 75 3 22 11 2 3 3
## 3 "East … 19 6 4 9 2 1 4
## 4 "Middl… 106 2 17 16 9 1 4
## 5 "Mount… 19 0 7 2 0 1 2
## 6 "New E… 41 1 0 12 4 2 2
## # … with 63 more variables: pecanTot <int>, pumpkinTot <int>, sweetpoTot <int>,
## # brusselTot <int>, carrotsTot <int>, cauliflTot <int>, cornTot <int>,
## # cornbreadTot <int>, fruitsalTot <int>, greenbTot <int>, macncheeTot <int>,
## # mashedTot <int>, rollsTot <int>, squashTot <int>, saladTot <int>,
## # yamsTot <int>, n <int>, appleProp <dbl>, buttermilkProp <dbl>,
## # cherryProp <dbl>, chocoProp <dbl>, cocoProp <dbl>, keylimeProp <dbl>,
## # peachProp <dbl>, pecanProp <dbl>, pumpkinProp <dbl>, sweetpoProp <dbl>,
## # brusselProp <dbl>, carrotsProp <dbl>, cauliflProp <dbl>, cornProp <dbl>,
## # cornbreadProp <dbl>, fruitsalProp <dbl>, greenbProp <dbl>,
## # macncheeProp <dbl>, mashedProp <dbl>, rollsProp <dbl>, squashProp <dbl>,
## # saladProp <dbl>, yamsProp <dbl>, appleDiff2 <dbl>, buttermilkDiff2 <dbl>,
## # cherryDiff2 <dbl>, chocoDiff2 <dbl>, cocoDiff2 <dbl>, keylimeDiff2 <dbl>,
## # peachDiff2 <dbl>, pecanDiff2 <dbl>, pumpkinDiff2 <dbl>, sweetpoDiff2 <dbl>,
## # brusselDiff2 <dbl>, carrotsDiff2 <dbl>, cauliflDiff2 <dbl>,
## # cornDiff2 <dbl>, cornbreadDiff2 <dbl>, fruitsalDiff2 <dbl>,
## # greenbDiff2 <dbl>, macncheeDiff2 <dbl>, mashedDiff2 <dbl>,
## # rollsDiff2 <dbl>, squashDiff2 <dbl>, saladDiff2 <dbl>, yamsDiff2 <dbl>
divPie2$favFlavor<-""
divPie2$favSide<-""
for(i in 1:dim(divPie2)[1]){
flavor=which(divPie2[i, 49:58]==max(divPie2[i, 49:58]))
if(flavor==1){
divPie2$favFlavor[i]<-"Apple"
}
if(flavor==2){
divPie2$favFlavor[i]<-"Buttlermilk"
}
if(flavor==3){
divPie2$favFlavor[i]<-"Cherry"
}
if(flavor==4){
divPie2$favFlavor[i]<-"Chocolate"
}
if(flavor==5){
divPie2$favFlavor[i]<-"Coconut"
}
if(flavor==6){
divPie2$favFlavor[i]<-"Keylime"
}
if(flavor==7){
divPie2$favFlavor[i]<-"Peach"
}
if(flavor==8){
divPie2$favFlavor[i]<-"Pecan"
}
if(flavor==9){
divPie2$favFlavor[i]<-"Pumpkin"
}
if(flavor==10){
divPie2$favFlavor[i]<-"Sweet Potato"
}
side=which(divPie2[i, 59:71]==max(divPie2[i, 59:71]))
if(side==1){
divPie2$favSide[i]<-"Brussel Sprouts"
}
if(side==2){
divPie2$favSide[i]<-"Carrots"
}
if(side==3){
divPie2$favSide[i]<-"Cauliflower"
}
if(side==4){
divPie2$favSide[i]<-"Corn"
}
if(side==5){
divPie2$favSide[i]<-"Cornbread"
}
if(side==6){
divPie2$favSide[i]<-"Fruit Salad"
}
if(side==7){
divPie2$favSide[i]<-"Green Beans"
}
if(side==8){
divPie2$favSide[i]<-"Mac N Cheese"
}
if(side==9){
divPie2$favSide[i]<-"Mashed Potatoes"
}
if(side==10){
divPie2$favSide[i]<-"Rolls"
}
if(side==11){
divPie2$favSide[i]<-"Squash"
}
if(side==12){
divPie2$favSide[i]<-"Salad"
}
if(side==13){
divPie2$favSide[i]<-"Yams"
}
}
favorites<-divPie2%>%
select(DivName, favFlavor, favSide)%>%
mutate(DivName=paste(DivName, " Division", sep=""))
favorites
## # A tibble: 10 x 3
## DivName favFlavor favSide
## <chr> <chr> <chr>
## 1 " Division" Coconut Salad
## 2 "East North Central Division" Pumpkin Rolls
## 3 "East South Central Division" Pecan Mac N Cheese
## 4 "Middle Atlantic Division" Apple Squash
## 5 "Mountain Division" Pecan Salad
## 6 "New England Division" Apple Squash
## 7 "Pacific Division" Cherry Salad
## 8 "South Atlantic Division" Sweet Potato Mac N Cheese
## 9 "West North Central Division" Pumpkin Green Beans
## 10 "West South Central Division" Pecan Cornbread
#install.packages("usmap")
library(usmap)
## Warning: package 'usmap' was built under R version 3.6.2
states <- usmap::us_map()
fips<-read.csv("https://raw.githubusercontent.com/kitadasmalley/FA2020_DataViz/main/data/stateFIPS.csv",
header=TRUE)
geoPie<-fips%>%
left_join(favorites)
## Joining, by = "DivName"
foodStates<-states %>%
mutate(Name=full)%>%
left_join(geoPie)
## Joining, by = "Name"
geom_polygon
foodStates%>%
ggplot(aes(x, y, group = group)) +
geom_polygon(aes(fill = as.factor(favSide)),color="black")+
theme_bw()+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())+
labs(x="", y = "",
caption = "(Based on data from fivethirtyeight)",
fill="Side Dish",
title="Side Dishes of American's Regions",
subtitle = "Most disproportionately common Thanksgiving side dishes")
foodStates%>%
ggplot(aes(x, y, group = group)) +
geom_polygon(aes(fill = as.factor(favFlavor)),color="black")+
theme_bw()+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())+
labs(x="", y = "",
caption = "(Based on data from fivethirtyeight)",
fill="Pie Flavor",
title="Pie Flavor of American's Regions",
subtitle = "Most disproportionately common Thanksgiving pie flavor")
This graphic is not complete yet!
(Thank you for the colors Sarah Abadi)
Using colormeter, match colors and add details; colors = turqouise = 4DB9B2 Burnt orange = E58764 Mustard = E2BC38 Green = 95C05D Squash Purple = DA8AB9 Blue = 7899D0
scale <- c("#E58764",
"#E2BC38",
"#7899D0",
"#95C05D",
"#4DB9B2",
"#DA8AB9")
Gray lines = #989798
ggplot(foodStates, aes(x,y, group = group, fill = as.factor(favSide))) +
geom_polygon(color = "#989798") +
coord_fixed() +
theme_gray() +
scale_fill_manual("Side Dishes",values = scale) +
theme(axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#ECEDEC"),
legend.background = element_rect(fill = "#ECEDEC")
)
add labels and titles
ggplot(foodStates, aes(x,y, group = group, fill = as.factor(favSide))) +
geom_polygon(color = "#989798") +
coord_fixed() +
theme_gray() +
scale_fill_manual("Side Dishes", values = scale) +
theme(axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#ECEDEC"),
legend.background = element_rect(fill = "#ECEDEC")
) +
labs(title = "Side Dishes Of America's Regions", subtitle = "Most disproportionately common Thanksgiving side dish by region") +
theme(plot.title = element_text(face = "bold", size = 15,),
plot.subtitle = element_text(size = 12))+
#add survey label
#annotate("text",
#label = "SURVEY DATES",
#size = 3,
#fontface = "bold",
#color = "#67696A",
#hjust = 0) +
#need to assign place on map..
annotate("text",
# x = -2950000,
x = -2400000,
y=1500000,
label = "SURVEY DATES",
size = 3,
fontface = "bold",
color = "#67696A",
hjust = 0) +
annotate("text",
x = -2350000,
y = 1200000,
label = "11/17/2015",
size = 3.5,
family = "mono",
color = "#67696A",
hjust = 0) +
annotate("text",
x = -270000,
y = 1455000,
label = "NO. OF RESPONDENTS",
size = 3,
fontface = "bold",
color = "#67696A",
hjust = 0) +
annotate("text",
x = -250000,
y = 1200000,
label = "931",
size = 3.5,
family = "mono",
color = "#67696A",
hjust = 0)