Based on data from The Ratio of Macronutrients, Not Caloric Intake, Dictates Cardiometabolic Health, Aging, and Longevity in Ad Libitum-Fed Mice
I have downloaded PDFs of both the paper and the supplemental material (as well as an xslx spreadsheet).
Use of Trilinear/Ternary plot suggested by (looks like this is done using the klaR package):
Diet details
Survival by diet
Notice that the highest median lifespan is for the High energy content version of diet 9 (42P/29C/29F).
Not working 8/9/14. Why? Turned off eval for now.
library(ggtern)
# survival_all <- read.csv("C:/Users/rseiter/Documents/Health/Nutrition/The Ratio of Macronutrients, Not Caloric Intake/survival.csv")
survival_all <- read.csv("~/Health/Nutrition/The Ratio of Macronutrients, Not Caloric Intake/survival.csv")
survival_all$Protein <- as.numeric(survival_all$Protein)
survival_all$Energy <- as.numeric(survival_all$Energy)
energy <- "HIGH"
survival <- subset(survival_all, Energy.Density==energy)
output <- ggtern(data=survival,aes(x=Protein,y=Carb,z=Fat),aes(x,y,z)) +
stat_density2d(geom="polygon",
n=400,
aes(fill=..level..,
weight=survival$Median.lifespan,
alpha=abs(..level..)),
binwidth=100) +
# facet_grid(survival$Energy.Density ~ .) + # Why failing?
geom_density2d(aes(weight=survival$Median.lifespan,color=..level..),
n=400,
binwidth=100) +
geom_point(aes(fill=survival$Median.lifespan),color="black",size=6,shape=21) +
geom_text(aes(label=Diet),size=4) +
# facet_wrap(survival$Energy.Density ~ ) + # Why failing?
scale_fill_gradient(low="yellow",high="red") +
scale_color_gradient(low="yellow",high="red") +
theme_rgbw() +
percent_custom("%") + #make ternary scales on custom %
theme(legend.justification=c(0,1), legend.position=c(0,1)) +
guides(fill = guide_colorbar(order=1),
alpha= guide_legend(order=2),
color="none") +
labs( title= paste("Median Lifespan by Dietary Composition -", energy, "Energy"),
fill = "Median Lifespan", alpha="Median Lifespan") # Why fill AND alpha?
# Focus on our space. Had to change/fix rounding to make this work right.
# Why problem with generating contours?
# I actually find the full plot more informative.
# last_plot() + coord_tern(Tlim=c(.2,.75),Llim=c(.05,0.6),Rlim=c(.2,0.75)) +
# labs(title=paste("Refocused Median Lifespan by Dietary Composition -", energy, "Energy"))
summary(output)
output
Why is rendering failing for this?
plotMedianLifespan <- function (survival_all, energy) {
survival <- subset(survival_all, Energy.Density==energy)
output <- ggtern(data=survival,aes(x=Protein,y=Carb,z=Fat),aes(x,y,z)) +
stat_density2d(geom="polygon",
n=400,
aes(fill=..level..,
weight=survival$Median.lifespan,
alpha=abs(..level..)),
binwidth=100) +
# facet_grid(survival$Energy.Density ~ .) + # Why failing?
geom_density2d(aes(weight=survival$Median.lifespan,color=..level..),
n=400,
binwidth=100) +
geom_point(aes(fill=survival$Median.lifespan),color="black",size=6,shape=21) +
geom_text(aes(label=Diet),size=4) +
# facet_wrap(survival$Energy.Density ~ ) + # Why failing?
scale_fill_gradient(low="yellow",high="red") +
scale_color_gradient(low="yellow",high="red") +
theme_rgbw() +
percent_custom("%") + #make ternary scales on custom %
theme(legend.justification=c(0,1), legend.position=c(0,1)) +
guides(fill = guide_colorbar(order=1),
alpha= guide_legend(order=2),
color="none") +
labs( title= paste("Median Lifespan by Dietary Composition -", energy, "Energy"),
fill = "Median Lifespan", alpha="Median Lifespan") # Why fill AND alpha?
# Focus on our space. Had to change/fix rounding to make this work right.
# Why problem with generating contours?
# I actually find the full plot more informative.
# last_plot() + coord_tern(Tlim=c(.2,.75),Llim=c(.05,0.6),Rlim=c(.2,0.75)) +
# labs(title=paste("Refocused Median Lifespan by Dietary Composition -", energy, "Energy"))
# Render here directly?
(output)
return(output)
}
# This would be better done with faceting
for (energy in c("LOW", "MEDIUM", "HIGH")) {
print(energy)
output <- plotMedianLifespan(survival_all, energy)
summary(output)
# Render
output
}