Function Repository Resource:

NutrientComparisonBarChart

Source Notebook

Create a dual bar chart comparing the calories and macronutrients in a list of foods

Contributed by: Gay Wilson

ResourceFunction["NutrientComparisonBarChart"][foods]

returns nutrition information in BarChart form for a list of foods.

Details and Options

NutrientComparisonBarChart returns a pair of bar charts. The first shows calories, and the second shows macronutrient content (protein, carbohydrates, fat, fiber).
The following options are supported:
ChartLabelsBeforeplacement of food names
ChartStyleAutomaticgraphics style for charts
ChartLegendsBelowplacement of nutrient properties
BarOriginLeftorigin placement for bars
BarSpacingAutomaticspacing between bars and bar groups
FontSize10font size of chart labels and legends
PlotLabel""optional overall label for both charts
ImageSize600overall image size expressed in points
ImageMarginsAutomaticabsolute margins around image
BackgroundAutomaticbackground color for the charts

Examples

Basic Examples (2) 

Compare the relative calories and macronutrients of raw fruits:

In[1]:=
ResourceFunction[
 "NutrientComparisonBarChart"][{"raw apple", "raw banana", "raw pear",
   "raw papaya", "raw raspberry", "raw strawberry"}]
Out[1]=

Visualize the nutrients in high-protein foods with a customized chart design:

In[2]:=
ResourceFunction[
 "NutrientComparisonBarChart"][{"braised beef", "cooked lentils", "boiled eggs", "peanut butter", "fried tofu", "grilled chicken"}, ChartStyle -> "Pastel", BarSpacing -> "None", PlotLabel -> "High-Protein Foods", FontSize -> 12]
Out[2]=

Scope (1) 

You can use Wolfram Language food entities directly, mapping the entities to food strings for the chart labels:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/be54f76c-d2ae-4198-9d79-e7175496f380"]
Out[3]=

Options (1) 

Create a vertical bar chart of grains with specified image size and labelings:

In[4]:=
ResourceFunction[
 "NutrientComparisonBarChart"][{"wheat", "rolled oats", "rye grain", "raw barley", "dry bulgur", "raw millet"}, BarOrigin -> Bottom, ChartLabels -> Below, ChartLegends -> Above, ImageSize -> Medium]
Out[4]=

Neat Examples (1) 

Have fun with the ChartStyle options named for foods, such as AvocadoColors, CandyColors, CherryTones, CoffeeTones, FruitPunchColors, MintColors, PlumColors and WatermelonColors:

In[5]:=
ResourceFunction[
 "NutrientComparisonBarChart"][{"cherry", "orange", "pineapple", "plum"}, ImageSize -> Medium, ChartStyle -> "FruitPunchColors"]
Out[5]=
In[6]:=
ResourceFunction[
 "NutrientComparisonBarChart"][{"brussel sprouts", "broccoli", "kale",
   "avocado"}, ImageSize -> Medium, ChartStyle -> "AvocadoColors"]
Out[6]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 10 May 2024
  • 1.0.0 – 04 March 2024

Related Resources

License Information