Analyze, Visualize, and Compare "Superfoods"
Superfoods are foods that are very high in one or more nutrients. This example defines a set of superfoods, then contrasts them with more "typical" foods using food data from the Wolfram Knowledgebase. Finally, it constructs an insignia appropriate for foods worthy of the "super" epithet.
First, define a list of superfoods containing the nutrients for which they are known.
superfoodsRawData = {{"greek yogurt", {"TotalProtein"}}, {"quinoa", \
{"TotalProtein"}}, {"blueberries", {"TotalFiber",
"VitaminC"}}, {"kale", {"TotalFiber", "Calcium",
"Iron"}}, {"chia", {"Magnesium", "Iron", "Calcium",
"Potassium"}}, {"oatmeal", {"TotalFiber"}}, {"broccoli", \
{"TotalFiber", "VitaminC",
"TotalFolate"}}, {"strawberries", {"VitaminC"}}, {"salmon", \
{"TotalProtein"}}, {"watermelon", {"TotalSugar", "VitaminA",
"VitaminC", "TotalCalories"}}, {"lima beans", {"TotalFiber"}},
{"edamame", {"TotalFiber"}}, {"spinach", {"Calcium",
"VitaminK"}}, {"pistachios", {"TotalProtein", "TotalFiber",
"Potassium"}}, {"eggs", {"TotalProtein"}}, {"almonds", \
{"TotalFiber", "Potassium", "Calcium", "VitaminE", "Magnesium",
"Iron"}}, {"pumpkin", {"BetaCarotene"}}, {"apples", \
{"TotalFiber", "TotalCalories"}}, {"lentils", {"TotalProtein",
"Iron"}}};
Convert this to a Dataset for easier computation.
superfoodsDatset =
Dataset[<|"Food" -> #1, "Nutrients" -> #2|> & @@@ superfoodsRawData]
Use Interpreter to get Wolfram Language entities for the superfoods.
superfoodsDatset1 =
superfoodsDatset[All,
KeySort[Prepend[#, <|
"FoodEntity" -> Interpreter["Food"][#Food]|>]] &];
List the nutrients.
Union @@ Normal[superfoodsDatset1[[All, "Nutrients"]]]
Create rules to convert the given nutrients to their appropriate properties.
superfoodsDatset2 =
superfoodsDatset1 /.
AssociationMap[
EntityProperty["Food", "Relative" <> # <> "Content"] &,
Union @@ Normal[superfoodsDatset1[[All, "Nutrients"]]]]
Find the most common nutrients in the Dataset.
mostCommonProperties =
superfoodsDatset2[Counts[Flatten[#]] &, "Nutrients"][TakeLargest[5]]
Find superfoods known for being high in fiber and compare them to nearly 9000 other foods. Visualize as a smoothed histogram, where the gray curve shows the probability density function of fiber content for most foods.
fiberDataset =
superfoodsDatset2[
Select[ContainsAny[#Nutrients, {EntityProperty["Food",
"RelativeTotalFiberContent"]}] &], KeyDrop["Nutrients"]];
Do the same process for protein-rich superfoods.
proteinDataset =
superfoodsDatset2[
Select[ContainsAny[#Nutrients, {EntityProperty["Food",
"RelativeTotalProteinContent"]}] &], KeyDrop["Nutrients"]];
Create a superfoods insignia, beginning with a set of superfood images.
GraphicsGrid[
Partition[
ims = EntityValue[
Cases[superfoodsDatset2[All, "FoodEntity"] // Normal,
Entity["FoodType", _], Infinity], "Image"], UpTo[5]]]
As the background, use a shape resembling that of a well-known super.
Entity["Lamina", "SupermanInsigniaLamina"]["Image"] // ImageCrop
Use some simple image processing to convert it to a background.
background =
ColorNegate[
Binarize[Entity["Lamina", "SupermanInsigniaLamina"]["Image"], .99]]
Create a "word cloud" consisting of superfoods.
wc = WordCloud[(RandomReal[{0.6, 1.2}] -> #) & /@ ims, background]
Combine the word cloud and background.
ImageMultiply[{ColorReplace[background, Black -> LightGray], wc}]