It is first important to look at the data and get a sense of what questions to ask in the first place
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.5 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
turkeydata<- read.csv("https://raw.githubusercontent.com/kitadasmalley/FA2020_DataViz/main/data/useThanks.csv",header=TRUE)
glimpse(turkeydata)
## Rows: 1,058
## Columns: 83
## $ id <dbl> 4337954960, 4337951949, 4337935621, 4337933040, 43…
## $ celebrate <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "…
## $ main <chr> "Turkey", "Turkey", "Turkey", "Turkey", "Tofurkey"…
## $ cooked <chr> "Baked", "Baked", "Roasted", "Baked", "Baked", "Ro…
## $ stuffing <chr> "Bread-based", "Bread-based", "Rice-based", "Bread…
## $ cranberry <chr> "None", "Other (please specify)", "Homemade", "Hom…
## $ gravy <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "…
## $ brussel.sprouts <chr> "", "", "Brussel sprouts", "Brussel sprouts", "Bru…
## $ carrots <chr> "Carrots", "", "Carrots", "", "", "Carrots", "", "…
## $ cauliflower <chr> "", "", "Cauliflower", "", "", "Cauliflower", "", …
## $ corn <chr> "", "Corn", "Corn", "", "", "Corn", "", "", "Corn"…
## $ cornbread <chr> "", "", "Cornbread", "Cornbread", "Cornbread", "Co…
## $ fruit.salad <chr> "", "", "", "", "", "Fruit salad", "Fruit salad", …
## $ green.beans <chr> "Green beans/green bean casserole", "Green beans/g…
## $ mac.n.cheese <chr> "Macaroni and cheese", "Macaroni and cheese", "", …
## $ mashed.potatoes <chr> "Mashed potatoes", "Mashed potatoes", "Mashed pota…
## $ rolls <chr> "", "Rolls/biscuits", "Rolls/biscuits", "Rolls/bis…
## $ squash <chr> "", "", "", "", "Squash", "Squash", "", "", "Squas…
## $ salad <chr> "", "Vegetable salad", "Vegetable salad", "Vegetab…
## $ yams.sweet.potato <chr> "Yams/sweet potato casserole", "Yams/sweet potato …
## $ apple.pie <chr> "Apple", "Apple", "Apple", "", "Apple", "", "Apple…
## $ buttermilk.pie <chr> "", "", "", "", "", "", "", "", "Buttermilk", "But…
## $ cherry.pie <chr> "", "", "Cherry", "", "", "", "", "", "", "", "", …
## $ chocolate.pie <chr> "", "Chocolate", "", "", "", "", "", "Chocolate", …
## $ coconut.pie <chr> "", "", "", "", "", "", "", "", "", "", "", "", ""…
## $ keylime.pie <chr> "", "", "", "", "", "", "", "", "", "", "", "", ""…
## $ peach.pie <chr> "", "", "Peach", "", "", "", "", "", "", "", "", "…
## $ pecan.pie <chr> "", "", "Pecan", "Pecan", "", "", "", "", "", "", …
## $ pumpkin.pie <chr> "", "Pumpkin", "Pumpkin", "Pumpkin", "Pumpkin", ""…
## $ sweet.potato.pie <chr> "", "", "Sweet Potato", "", "", "Sweet Potato", ""…
## $ apple.cobbler <chr> "", "", "", "", "", "", "", "", "", "", "", "", ""…
## $ blondies <chr> "", "", "", "", "", "", "", "", "", "", "", "", ""…
## $ brownies <chr> "", "", "Brownies", "", "", "", "", "", "", "", ""…
## $ carrot.cake <chr> "", "", "Carrot cake", "", "", "", "", "", "", "",…
## $ cheesecake <chr> "Cheesecake", "Cheesecake", "", "", "", "Cheesecak…
## $ cookies <chr> "Cookies", "Cookies", "Cookies", "", "", "", "Cook…
## $ fudge <chr> "", "", "Fudge", "", "", "", "", "", "", "", "", "…
## $ ice.cream <chr> "Ice cream", "", "Ice cream", "", "", "", "", "", …
## $ peach.cobbler <chr> "", "", "", "", "", "", "", "", "", "", "", "", "P…
## $ pray <chr> "Yes", "Yes", "Yes", "No", "No", "Yes", "No", "No"…
## $ friendsgiving <chr> "No", "No", "Yes", "No", "No", "Yes", "No", "Yes",…
## $ black.friday <chr> "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "Yes…
## $ area.live <chr> "Suburban", "Rural", "Suburban", "Urban", "Urban",…
## $ age <chr> "18 - 29", "18 - 29", "18 - 29", "30 - 44", "30 - …
## $ gender <chr> "Male", "Female", "Male", "Male", "Male", "Male", …
## $ income <chr> "$75,000 to $99,999", "$50,000 to $74,999", "$0 to…
## $ DivName <chr> "Middle Atlantic", "East South Central", "Mountain…
## $ celebrate01 <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,…
## $ gravy01 <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, NA, 0, 1, 1, 1, 1, 1…
## $ friendsgiving01 <int> 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, NA, 0, 0, 1, 0, 1, 1…
## $ black.friday01 <int> 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, NA, 0, 0, 1, 0, 0, 1…
## $ brussel.sprouts01 <int> 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ carrots01 <int> 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ cauliflower01 <int> 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ corn01 <int> 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1,…
## $ cornbread01 <int> 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,…
## $ fruit.salad01 <int> 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ green.beans01 <int> 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1,…
## $ mac.n.cheese01 <int> 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,…
## $ mashed.potatoes01 <int> 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1,…
## $ rolls01 <int> 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1,…
## $ squash01 <int> 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,…
## $ salad01 <int> 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,…
## $ yams.sweet.potato01 <int> 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1,…
## $ apple.pie01 <int> 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0,…
## $ buttermilk.pie01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,…
## $ cherry.pie01 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,…
## $ chocolate.pie01 <int> 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0,…
## $ coconut.pie01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ keylime.pie01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ peach.pie01 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,…
## $ pecan.pie01 <int> 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1,…
## $ pumpkin.pie01 <int> 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0,…
## $ sweet.potato.pie01 <int> 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0,…
## $ apple.cobbler01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ blondies01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ brownies01 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,…
## $ carrot.cake01 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,…
## $ cheesecake01 <int> 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ cookies01 <int> 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0,…
## $ fudge01 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ice.cream01 <int> 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ peach.cobbler01 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,…
As a vegitarian, thanksgiving has always been a bit tricky when it comes to what I can eat. Many of the regular dishes contain meat or some kind of animal broth. Turkey and stuffing have always been the main dishes at my house and there’s something about filling up on green beans that just doesn’t seem to fit the holiday. I was surprised to see so many people serve “Tofurkey” or tofu turkey (or some other meat substitute) at thanksgiving! This is what caught my interest and is what I was to focus my graphic on.
My question is
I’m going to try to make a map, we’ll see how it goes
#Group_by and Summarise
#Find the total number of households who serve each of the menu items, by region
#trying to write a for loop
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}
region<-turkeydata$DivName
dish<-turkeydata$main
for (x in region) {
for (y in dish)
}
#working on hint
totalnumfood<-turkeydata %>%
group_by(DivName=="East North Central")%>%
group_by(main)%>%
summarise(n=n(), sum=sum(n))
sum(totalnumfood$n)
totalnumfood<-turkeydata %>%
group_by(DivName %in% c("East North Central",
"East South Central",
"Middle Atlantic",
"Mountain",
"New England",
"Pacific",
"South Atlantic",
"West North Central",
"West South Central")) #looks at each region
summarise(n=n())
View(totalnumfood)
totalnumfood<-turkeydata %>%
group_by(DivName, main) #looks at each region
summarise(count(turkeydata$main=="tofurkey"))
totalnumfood<-turkeydata %>%
group_by(DivName=="East North Central" | DivName==
"East South Central")%>% #looks at each region
n_distinct(main)
#Find the total number of houesholds in each region
#Mutate
#Figuring out the 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
Update: It did not go well… Giving up for now, trying something different
ggplot(turkeydata, aes(main))+
geom_bar()
#going to filter out the blanks and "Other(please specify)"
turkeydata<-turkeydata%>%
filter(main !="Other (please specify)" )%>%
filter(main != "")
ggplot(turkeydata, aes(main))+
geom_bar() #much better!
Maybe a better question is what do different regions eat besides turkey as a main dish?
#Take out the turkeys! Also taking out "I don't know"-> we dont need to consider mystery meats
notsoturkeydata<-turkeydata%>%
filter(main !="Turkey" )%>%
filter(main!= "I don't know")
#facet by region
ggplot(notsoturkeydata, aes(main))+
geom_bar()+
facet_wrap(~DivName)
#filter out the blanks
notsoturkeydata<-notsoturkeydata%>%
filter(DivName != "")
ggplot(notsoturkeydata, aes(main))+
geom_bar()+
facet_wrap(~DivName)
Now we’re cookin’! (get it? because thanksgiving?). The above plot is definently not the prettiest I’ve seen but it’s good for an inital plot.
I’m going to try to make my own color palette! I want to use a qualitative color pallette since there is no inherent ranking in these categories (I thought I could try ranking them on which is healthiest to eat but I think that would be too hard). the plan is to color the bars based on the color of the animal (ham/pork=pink). All the colors are different hues so they are easily distinguishable but chroma/luminance may vary between colors since I had to adjust some of my colors to be colorblind friendly.
# install.packages("RColorBrewer")
library(RColorBrewer)
library(colorspace)
# To use for fills, add
ggplot(notsoturkeydata, aes(main, fill=main))+
geom_bar()+
facet_wrap(~DivName)+
scale_fill_manual(values=c("#F1BF24", "#D191E4", "#61400E","#4A8C0B", "#FFFFFF"))
Wahoo! Okay so pork is a little purple looking but any other pink isn’t colorblind friendly so I’m going to call it a win.
What do you find confusing? Labeling could be a lot better, stuff is hard to read I think it could be fun to include animal images above the plots but we’ll see
What do you find distracting? Elements of a polished plot:
All text should be unobscured and readable (make sure it’s big enough) Need to fix labels
All legends should be fully viewable and readable
Grid (major and minor breaks) should be meaningful and not distracting I think the background grid is confusing
Aspect ratio of plot should be appropriate Remember everything is open to polishing
ggplot(notsoturkeydata, aes(main, fill=main))+
geom_bar()+
facet_wrap(~DivName)+
scale_fill_manual(values=c("#F1BF24", "#D191E4", "#61400E","#4A8C0B", "#ABABAB"))+ #unable to see white, ducks can be grey
coord_flip()+ #helpful for reading axis
labs(y="Number of Households", x = "Non-Turkey Main Dish",
title= "Take a PECK at these Main Dishes", #get it? peck? I worked longer on that than necessary
subtitle = "What Americans are eating besides turkey",
caption="(Based on Thanksgiving Kaggle data from 2015)",
fill= "Main Dish"
)+
theme_classic()+
theme(
plot.title=element_text(face="bold", size=15),
plot.subtitle=element_text(size=12),
plot.caption = element_text(size=9),
plot.margin = margin(0.7,0.4,0.9,0.5,"cm")
)
I also want to note that I know the main dish legend on the right is a repeat of the y axis information but the graph makes more sense with it so I decided to leave it in.
#I tried to include a cute image key but it didn't work :(
install.packages("jpeg")
install.packages("grid")
install.packages("patchwork")
library(patchwork)
library(jpeg)
library(grid)
install.packages("png")
library(png)
library(grid)
img <- readPNG(system.file("img", "AnimalsMidterm.png", package="png"))
g <- rasterGrob(img, interpolate=TRUE)
qplot(1:10, 1:10, geom="blank") +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_point()
# specifying the image path
path <- "/Users/Ellie/Desktop/AnimalsMidterm.jpeg"
# read the jpef file from device
img <- readJPEG(path, native = TRUE)
# adding image to graph
img_graph <- graph +
inset_element(p = img,
left = 0.05,
bottom = 0.65,
right = 0.5,
top = 0.95)
# printing graph with image
print (img_graph)