for(i in 1:length(plot.groups)) {
# tmp.subtitle =
#   paste0("Calories: ",kcal.dat$Percent.Calories[kcal.dat$Food.Group %in% plot.groups[i]],
#          "%\nProtein: ",protein.dat$Percent.Protein[kcal.dat$Food.Group %in% plot.groups[i]],"%")
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = plot.groups[i]) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
# theme(legend.position = 'bottom')
# Adding to the plot list
plot.list[[plot.groups[i]]] = tmp.plot
}
# Sorting plot groups alphabetically
plot.groups <- sort(plot.groups)
# Configuring plots into a 3x3 matrix
out.plot =
plot_grid(plot.list[[plot.groups[1]]], plot.list[[plot.groups[2]]], plot.list[[plot.groups[3]]],
plot.list[[plot.groups[4]]], plot.list[[plot.groups[5]]], plot.list[[plot.groups[6]]],
plot.list[[plot.groups[7]]], plot.list[[plot.groups[8]]], plot.list[[plot.groups[9]]],
nrow = 3, align = 'hv')
# Clearing plotting window
dev.off()
dev.off()
# Plotting
out.plot
Sys.sleep(20)
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Figure 4 Most Common Foods 95percent ellipses 29July2020.pdf",
width = 18, height = 15, units = 'cm')
length(out.dat$plot_group %in% plot.groups[i])
# Making plots in a list
plot.list = list()
for(i in 1:length(plot.groups)) {
# tmp.subtitle =
#   paste0("Calories: ",kcal.dat$Percent.Calories[kcal.dat$Food.Group %in% plot.groups[i]],
#          "%\nProtein: ",protein.dat$Percent.Protein[kcal.dat$Food.Group %in% plot.groups[i]],"%")
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i]),'\N',length(out.dat$plot_group %in% plot.groups[i])) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
# theme(legend.position = 'bottom')
# Adding to the plot list
plot.list[[plot.groups[i]]] = tmp.plot
}
# Sorting plot groups alphabetically
plot.groups <- sort(plot.groups)
paste0(plot.groups[i]),'\N',length(out.dat$plot_group %in% plot.groups[i])
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i],'\N',length(out.dat$plot_group %in% plot.groups[i]))) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i],'\N',length(out.dat$plot_group %in% plot.groups[i]))) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
paste0(plot.groups[i],'\N',length(out.dat$plot_group %in% plot.groups[i]))
paste0(plot.groups[i],'\\N',length(out.dat$plot_group %in% plot.groups[i]))
paste0(plot.groups[i],'\n',length(out.dat$plot_group %in% plot.groups[i]))
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i],'\n','n = (',length(out.dat$plot_group %in% plot.groups[i]),')')) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
tmp.plot
# Making plots in a list
plot.list = list()
for(i in 1:length(plot.groups)) {
# tmp.subtitle =
#   paste0("Calories: ",kcal.dat$Percent.Calories[kcal.dat$Food.Group %in% plot.groups[i]],
#          "%\nProtein: ",protein.dat$Percent.Protein[kcal.dat$Food.Group %in% plot.groups[i]],"%")
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i],'\n','n = (',length(out.dat$plot_group %in% plot.groups[i]),')')) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
# theme(legend.position = 'bottom')
# Adding to the plot list
plot.list[[plot.groups[i]]] = tmp.plot
}
# Sorting plot groups alphabetically
plot.groups <- sort(plot.groups)
# Configuring plots into a 3x3 matrix
out.plot =
plot_grid(plot.list[[plot.groups[1]]], plot.list[[plot.groups[2]]], plot.list[[plot.groups[3]]],
plot.list[[plot.groups[4]]], plot.list[[plot.groups[5]]], plot.list[[plot.groups[6]]],
plot.list[[plot.groups[7]]], plot.list[[plot.groups[8]]], plot.list[[plot.groups[9]]],
nrow = 3, align = 'hv')
# Clearing plotting window
dev.off()
dev.off()
# Plotting
out.plot
Sys.sleep(20)
length(out.dat$plot_group %in% plot.groups[i])
i
i = 1
length(out.dat$plot_group %in% plot.groups[i])
plot.groups[i]
i = 22
i = 2
plot.groups[i]
table(out.dat$plot_group)
sum(out.dat$plot_group %in% plot.groups[i])
# Making plots in a list
plot.list = list()
for(i in 1:length(plot.groups)) {
# tmp.subtitle =
#   paste0("Calories: ",kcal.dat$Percent.Calories[kcal.dat$Food.Group %in% plot.groups[i]],
#          "%\nProtein: ",protein.dat$Percent.Protein[kcal.dat$Food.Group %in% plot.groups[i]],"%")
tmp.plot =
ggplot() +
# geom_hline(yintercept = .1, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .2, colour = 'grey25', alpha = .33) +
# geom_hline(yintercept = .5, colour = 'grey25', alpha = .33) +
stat_ellipse(data = out.dat,
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = (colour_plot)),
level = .95, alpha = .33) +
scale_colour_manual(values = (colour.palette),
labels = plot.groups) +
geom_point(data = out.dat %>% filter(plot_group %in% plot.groups[i]),
aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, group = product_name),
shape = 21, colour = colour.palette[i], size = 2, fill = colour.palette[i], alpha = .33) +
scale_y_continuous(trans = 'log10', limits = c(0.001,.65), breaks = c(.003,.03,.3)) +
scale_x_continuous(limits = c(0,1), expand = c(0,0)) +
labs(x = 'Nutrition Score', y = 'Environment Score (per 100g)', title = paste0(plot.groups[i],'\n','n = (',sum(out.dat$plot_group %in% plot.groups[i]),')')) +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(plot.title = element_text(size = 9)) +
theme(legend.position = 'none')
# theme(legend.position = 'bottom')
# Adding to the plot list
plot.list[[plot.groups[i]]] = tmp.plot
}
# Sorting plot groups alphabetically
plot.groups <- sort(plot.groups)
# Configuring plots into a 3x3 matrix
out.plot =
plot_grid(plot.list[[plot.groups[1]]], plot.list[[plot.groups[2]]], plot.list[[plot.groups[3]]],
plot.list[[plot.groups[4]]], plot.list[[plot.groups[5]]], plot.list[[plot.groups[6]]],
plot.list[[plot.groups[7]]], plot.list[[plot.groups[8]]], plot.list[[plot.groups[9]]],
nrow = 3, align = 'hv')
# Clearing plotting window
dev.off()
dev.off()
# Plotting
out.plot
Sys.sleep(20)
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Figure 4 Most Common Foods 95percent ellipses 12August2020.pdf",
width = 18, height = 15, units = 'cm')
dev.off()
# Tukey's HSD test to examine differences between groups
# Doing a tukey test
# Setting levels in out.dat
out.dat <-
transform(out.dat, plot_group = factor(plot_group, levels = sort(plot.groups)))
out.dat <-
out.dat[order(out.dat$plot_group),]
par(mar = c(2,12,2,2))
# Nutrition
model = lm(out.dat$NutriScore_Scaled ~ out.dat$plot_group)
ANOVA = aov(model)
TUKEY = TukeyHSD(x = ANOVA, 'out.dat$plot_group', conf.level = .95)
TUKEY
plot(TUKEY, cex = .25, cex.axis = .5, las = 1)
# Creating boxplot with labels
# I need to group the treatments that are not different each other together.
generate_label_df <- function(TUKEY, variable){
# Extract labels and factor levels from Tukey post-hoc
Tukey.levels <- TUKEY[[variable]][,4]
Tukey.labels <- data.frame(multcompLetters(Tukey.levels)['Letters'])
#I need to put the labels in the same order as in the boxplot :
Tukey.labels$treatment=rownames(Tukey.labels)
Tukey.labels=Tukey.labels[order(Tukey.labels$treatment) , ]
return(Tukey.labels)
}
# Apply the function on my dataset
LABELS_NUT <- generate_label_df(TUKEY , "out.dat$plot_group")
# Environment
model = lm(out.dat$TotEnv_100g_scaled ~ out.dat$plot_group)
ANOVA = aov(model)
TUKEY = TukeyHSD(x = ANOVA, 'out.dat$plot_group', conf.level = .95)
TUKEY
plot(TUKEY, cex = .25, cex.axis = .5, las = 1)
# Apply the function on my dataset
LABELS_ENV <- generate_label_df(TUKEY , "out.dat$plot_group")
# A panel of colors to draw each group with the same color :
my_colors <-
c("#88ccee","#cc6677","#ddcc77","#117733","#332288","#aa4499",
"#44aa99","#999933","#882255","661100","6699cc","888888")
my_colors <- my_colors[1:length(levels(LABELS$Letters))]
# Draw the basic boxplot
par(mar = c(10,5,2,5))
a <- boxplot(out.dat$NutriScore_Scaled ~ out.dat$plot_group,
ylim=c(min(out.dat$NutriScore_Scaled), 1.1*max(out.dat$NutriScore_Scaled)),
col=my_colors[as.numeric(LABELS[,1])],
ylab="Nutrition Score", main="",
las = 2, cex.axis = .6)
# I want to write the letter over each box. Over is how high I want to write it.
over <- 0.1*max( a$stats[nrow(a$stats),] )
#Add the labels
# text( c(1:nlevels(out.dat$plot_group)) , a$stats[nrow(a$stats),]+over , LABELS[,1]  , col=my_colors[as.numeric(LABELS[,1])] )
text( c(1:nlevels(out.dat$plot_group)) , .9, LABELS[,1]  , col=my_colors[as.numeric(LABELS[,1])] )
# Getting 95th percentile for each group
figs3.dat <-
out.dat %>%
group_by(plot_group) %>%
summarise(high_env = quantile(TotEnv_100g_scaled,.99, na.rm = TRUE),
high_nut = quantile(NutriScore_Scaled,.99, na.rm = TRUE)) %>%
left_join(., LABELS_NUT[1] %>% as.data.frame() %>% mutate(plot_group = rownames(.))) %>%
dplyr::rename(Letters_Nut = Letters) %>%
left_join(.,LABELS_ENV[1] %>% as.data.frame() %>% mutate(plot_group = rownames(.))) %>%
dplyr::rename(Letters_Env = Letters) %>%
transform(plot_group = factor(plot_group, levels = levels(out.dat$plot_group)))
# Turning tukey plots into boxplots
figs3_nut <-
ggplot(dat = out.dat, aes(x = plot_group, y = NutriScore_Scaled)) +
geom_boxplot() +
theme_classic() +
labs(y = 'Nutrition Score', x = NULL) +
geom_text(dat = figs3.dat, aes(x = plot_group, y = high_nut + c(.1,.05,.12,.09,.08,.075,.1,.14,.1), label = Letters_Nut)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
figs3_env <-
ggplot(dat = out.dat, aes(x = plot_group, y = TotEnv_100g_scaled)) +
geom_boxplot() +
theme_classic() +
labs(y = 'Environmental Score Score', x = NULL) +
geom_text(dat = figs3.dat, aes(x = plot_group, y = high_env + c(.2,.2,.05,.25,.01,.09,.25,.12,.01), label = Letters_Env)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_y_continuous(trans = 'log10', limits = c(.001,1), expand = c(0,0), breaks = c(.003,.03,.3))
figs3 <-
plot_grid(figs3_env, figs3_nut,
nrow = 2, align = 'hv')
figs3
a <- boxplot(out.dat$NutriScore_Scaled ~ out.dat$plot_group,
ylim=c(min(out.dat$NutriScore_Scaled), 1.1*max(out.dat$NutriScore_Scaled)),
col=my_colors[as.numeric(LABELS[,1])],
ylab="Nutrition Score", main="",
las = 2, cex.axis = .6)
# Summary stats
# Means
tmp.means <-
out.dat %>%
group_by(plot_group) %>%
summarise(env = mean(TotEnv_100g_scaled, na.rm = TRUE),
nut = mean(NutriScore_Scaled, na.rm = TRUE))
View(tmp.means)
View(dat.figs3)
View(figs3.dat)
# Quantiles
tmp.quantiles <-
out.dat %>%
group_by(plot_group) %>%
summarise(low_env = quantile(TotEnv_100g_scaled, .05, na.rm = TRUE),
high_env = quantile(TotEnv_100g_scaled, .95, na.rm = TRUE),
low_nut = quantile(NutriScore_Scaled, .05, na.rm = TRUE),
high_nut = quantile(NutriScore_Scaled, .95, na.rm = TRUE)) %>%
mutate(range_env = high_env / low_env,
range_nut = high_nut / low_nut)
View(tmp.quantiles)
# Plotting
out.plot
Sys.sleep(20)
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Figure 4 Most Common Foods 95percent ellipses 12August2020.pdf",
width = 18, height = 15, units = 'cm')
###
# Cookies and biscuits that contain chocolate
cookie.dat <-
out.dat %>%
filter(plot_group %in% 'Cookies and Biscuits')
nrow(cookie.dat)
plot.groups
###
# Cookies and biscuits that contain chocolate
cookie.dat <-
out.dat %>%
filter(plot_group %in% 'Cookies and biscuits')
nrow(cookie.dat)
names(stacked.dat)
stacked.dat.cookies <-
stacked.dat %>%
filter(product_name %in% cookie.dat$product_name) %>%
filter(grepl("Chocolate",Food_Category, ignore.case = TRUE))
nrow(stacked.dat.cookies)
stacked.dat.cookies <-
stacked.dat %>%
filter(product_name %in% cookie.dat$product_name) %>%
filter(grepl("Chocolate",Food_Category, ignore.case = TRUE)) %>%
dplyr::select(product_name, Food_Category) %>%
unique(.)
nrow(stacked.dat.cooies)
nrow(stacked.dat.cookies)
View(stacked.dat.cookies)
unique(stacked.dat.cookies$Food_Category)
cookie.dat <-
cookie.dat %>%
mutate(Chocolate = ifelse(product_name %in% stacked.dat.cookies$product_name, 'Yes','No'))
# Average Impacts
cookie.dat.sum <-
cookie.dat %>%
group_by(Chocolate) %>%
summarise(Avg_Env = mean(TotEnv_100g_scaled, na.rm = TRUE),
Avg_Nut = mean(NutriScore_Scaled, na.rm = TRUE))
View(cookie.dat.sum)
.0207/.010
.62/.55
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point()
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10')
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)')
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)') +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9))
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)') +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(legend.text = element_text(size = 9)) +
theme(legend.title = element_text(size = 9))
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)', colour = 'Contains Chocolate') +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(legend.text = element_text(size = 9)) +
theme(legend.title = element_text(size = 9))
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Supplemental Fig Chocolate vs Non Chocolate Biscuits.pdf",
height = 6, width = 10, units = 'cm')
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
# theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)', colour = 'Contains Chocolate') +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(legend.text = element_text(size = 9)) +
theme(legend.title = element_text(size = 9))
Sys.sleep(5)
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Supplemental Fig Chocolate vs Non Chocolate Biscuits.pdf",
height = 6, width = 10, units = 'cm')
# Plotting
ggplot(dat = cookie.dat, aes(x = NutriScore_Scaled, y = TotEnv_100g_scaled, colour = Chocolate)) +
geom_point() +
scale_y_continuous(trans = 'log10') +
theme(legend.position = 'bottom') +
labs(x = 'Nutrition Score',y = 'Total Environmental Score\n(per 100g)', colour = 'Contains Chocolate') +
theme(axis.text = element_text(size = 9)) +
theme(axis.title = element_text(size = 9)) +
theme(legend.text = element_text(size = 9)) +
theme(legend.title = element_text(size = 9))
Sys.sleep(5)
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Supplemental Fig Chocolate vs Non Chocolate Biscuits.pdf",
height = 10, width = 10, units = 'cm')
ggsave("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Figures/Supplemental Fig Chocolate vs Non Chocolate Biscuits.pdf",
height = 10, width = 15, units = 'cm')
t.test(x = cookie.dat$NutriScore_Scaled[cookie.dat$Chocolate %in% 'Yes'],
y = cookie.dat$NutriScore_Scaled[cookie.dat$Chocolate %in% 'No'])
t.test(x = cookie.dat$TotEnv_100g_scaled[cookie.dat$Chocolate %in% 'Yes'],
y = cookie.dat$TotEnv_100g_scaled[cookie.dat$Chocolate %in% 'No'])
t.test(x = cookie.dat$TotEnv_100g_scaled[cookie.dat$Chocolate %in% 'Yes'],
y = cookie.dat$TotEnv_100g_scaled[cookie.dat$Chocolate %in% 'No'])
t.test(x = cookie.dat$NutriScore_Scaled[cookie.dat$Chocolate %in% 'Yes'],
y = cookie.dat$NutriScore_Scaled[cookie.dat$Chocolate %in% 'No'])
length(unique(stacked.dat$product_name))
###
# Data
dat <- read.csv("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Managed_Data/Impacts by Product 29July2020.csv",
stringsAsFactors = FALSE)
length(unique(dat$product_name))
###
# Data
dat <-
read.csv("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Managed_Data/Impacts by Product 29July2020.csv",
stringsAsFactors = FALSE) %>%
filter(!is.na(TotEnv_100g_scaled)) %>%
filter(!is.na(NutriScore_scaled))
length(unique(dat$product_name))
###
# Data
dat <-
read.csv("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Managed_Data/Impacts by Product 29July2020.csv",
stringsAsFactors = FALSE) %>%
filter(!is.na(TotEnv_100g_scaled)) %>%
filter(!is.na(NutriScore_Scaled))
length(unique(dat$product_name))
unique(dat$Retailer)
lca.dat
# Importing data first
# LCA data set
lca.dat <-
read.csv("/Volumes/Citadel/Oxford/Research Projects/Env and Health Snapshot of FoodDB/Data Inputs/LCA_data_29July2020.csv",
stringsAsFactors = FALSE) %>%
dplyr::select(Food_Category = food.group,
Bio = Biodiversity_50th_percentile,
GHG = GHG_50th_percentile,
Eut = Eutrophication_50th_percentile,
WatScar = Scarcity_50th_percentile)
unique(lca.dat$Food_Category)
