Subscribe Bookmark


Jun 23, 2011

Visualizing pregnancy and post-baby weight loss with Graph Builder

My first favorite visualization from my JMP Discovery Summit poster was a multiple-element Graph Builder creation that tracked my weight trends through pregnancy, post-baby weight loss, and two and half years of weight maintenance. This seems like an especially appropriate time of year to share this graph since  so many New Year's resolutions include weight loss goals!

While BodyMedia provides a weight graph in their software and you can export weekly or monthly summaries of calorie-related measures in PDF format, it doesn't offer a unified graphic to track long-term weight changes along with deficit and macronutrient information. Although the final graph may look complicated, it's actually pretty easy to create it in Graph Builder once you know how. Xan Gregg, lead developer of Graph Builder in JMP and head of our Data Visualization group, actually recreated my final graph during part of his "Unlocking the Power of Graph Builder" talk at Discovery Summit 2014. (If you missed the conference, you can see the recording in the JMP User Community.)

In the early version of this graph shown below, I used points for weight measurements, with multiple weight measures stacked within weeks. I added bar elements to display average weekly percentages for the various macronutrients I tracked. I added a heat map to show the number of days out of each week that I ate in a calorie surplus or deficit, with red indicating more days in a particular range and blue indicating fewer. I used a smoother on the heat map and Y axis range lines to show the deficit and surplus ranges in 500 calorie increments. An X axis reference line showed the end date of my pregnancy.

Early version of main plot

Prior to creating the final version of this graph for my poster, I met with Xan, who recommended simplifying the presentation of this graph by:

  • Lightening axis reference lines so that they did not dominate the data.
  • Superimposing macronutrient percentage values in the same section of the graph using lines rather than showing them as separate bar graphs and simplifying the tick mark display.
  • Changing the variable type for macronutrient percentages so that they were displayed as percentages and not ratios.
  • Moving X axis labels to a horizontal orientation.
  • When we changed the macronutrient percentages to display as lines, I noticed a big problem. Connecting through the missing values for alcohol percentage gave the mistaken impression that I was drinking through my pregnancy! To fix this, Xan showed me that I could right click in the macronutrient line graph to display bars along with the lines. We then used the Variables section in the left side property pane of the Graph Builder window to adjust which graph elements were shown for each variable. I turned off the bars for protein, carbs and fat, and turned off the line for alcohol, and then adjusted the color of the alcohol bar to purple. We labeled each element with annotations from the Tools menu, right clicking to remove the annotation box outline, change its background color to white, and update the text color of the annotation to match each graph element. We also removed the bar display for total calories since it didn't add much to the overall story.

    Xan also recommended choosing a continuous color theme for the heat map element to replace the divergent red to blue theme. We both thought that the count of days spent within different deficit or surplus ranges was shown much more clearly by a continuous red to yellow color theme. Red indicated more days spent in a specified deficit or surplus range, while the lighter yellow meant fewer days spent in that range. Below is the final graph we created.

    Main poster graph

    I’ll confess to having used one JMP 12 axis feature to create this graph. Can you spot it?

    (I added a nested week variable to the X axis so that my data would be summarized by week. The JMP 12 feature I used was the ability to selectively turn off the labels so that week numbers didn’t appear in my graph. Without a doubt, you’ll hear more about these and other JMP axis settings updates when JMP 12 comes out! Check out Xan's preview of what's coming for Graph Builder in JMP 12.)

    I have collected my own calorie, weight and exercise data in notebooks during past weight loss efforts, and I've used this data-driven approach to lose 45 pounds prior to my second pregnancy. The graph above reveals what I already knew: I was in a calorie surplus during most of my pregnancy, and as a result I gained more than the recommended amount of weight. This happened even though I chose healthy foods and exercised. On the plus side, my son was born at a healthy 8 pounds, I gained less than I had during my first pregnancy, and I experienced fewer discomforts this time. But when I weighed myself three weeks after my son’s birth, I had to face the fact that about half of my pregnancy weight gain was baby and water weight and the other half was extra body fat. As you can see from the graph, it took six months of consistently eating less than I burned to lose the excess and arrive in my current maintenance weight range. The percentages of carbs, fat and protein I ate while in this post-pregnancy deficit didn't vary that greatly from the percentages noted during my pregnancy.

    If you have read the first post in this series, you know that I've experienced drastic weight swings in my lifetime, and I'm determined to avoid large swings going forward. Accordingly, I have examined my data on my past and present eating and activity patterns to learn what works for me to reach (and maintain) a healthy weight. First and most importantly, I have determined that I am most successful at loss and maintenance when I actively track my data. This takes less and less time as technology improves. I used to track my weight, diet and workout data all on paper , but most of my data collection has been automated by an activity monitor, food tracking app and wireless scale. I continue to track my workouts the old-fashioned way in notebooks, but the effort is minimal. I have even begun to examine my historical workout data in JMP....Stay tuned for posts on that topic in the future!

    I find that tracking my diet and fitness efforts provides daily accountability as well as data. When reviewing my historical data, I found that I would usually stop tracking during holidays or stressful times when travel and/or social commitments led me to over-indulge and skip workouts. I'd feel guilty, which would lead to negative self-talk, more excuses, and eventually to weight gain. I have worked actively for the past five years to overcome these tendencies, committing myself to enjoying social events and always logging what I eat without sinking into guilt. During busy times, I may cut down on workout length, but I always make an effort to do something rather than nothing.

    After monitoring my weight nearly daily for two years with a wireless scale, I have identified which factors can cause day to day fluctuations (e.g., water changes due to hydration, workouts, sodium and carbs) and which cause true long-term weight trends (e.g., eating in a surplus or deficit). This understanding has helped me to worry less about small short-term fluctuations, pay attention to the bigger picture, and maintain my weight within a small range for the past 2 ½ years. I now understand the daily eating and activity patterns that can keep me within my maintenance zone. When I see myself drifting upward in weight or calories, I can recognize the pattern relatively quickly and adjust the numbers to get back to the range where I want to be.

    To reproduce this graph with your own data in Graph Builder, open a data table containing a daily surplus/deficit measure (which I calculated from my data with the formula Calories Burned-Calories Consumed), macronutrient percentages, and body weight where each rows contains data from a single day. (Of course, you could also make smaller graphs containing only a few of these measures if you don't have them all.)

    If your data table doesn't have Year and Month variables, you can create these from your Date variable by right-clicking on your date in the Graph Builder column chooser and adding them as new transform columns from the Date Time menu. This will extract the month from the Date column, and you can use a Value Ordering property on the Month variable to create a column of ordered short Month names. I made sure that Year and Month Name were both specified as Ordinal before adding them to the same axis.

    To replicate this graph, open Graph Builder and drag:

    • Year to the X axis.
    • Month Name to the X Axis (just above Year, so the axis shows Month Name nested within Year).
    • Week to the X axis (just above Month name, so Week is nested within Month).
    • Weight to the Y axis.
    • Deficit/surplus to the Y axis below weight (so that they appear in separate sections). Drag the heat map element into the deficit/surplus section. Right-click on the color gradient element in the Graph Builder legend on the right to change the color theme to a continuous one; I chose Muted Yellow to Red.
    • Macronutrient percentage columns (e.g., fat, carbs, protein, alcohol) into the same section below the heat map element. Right-click (or drag in) to change the element type to bar and also add lines. In the right-click menu in that section of the graph, or in the left size variables tab, remove the bars for fat, carbs and protein. Remove the line for alcohol.
    • To complete the graph, adjust your Y-axis, graph title and axis titles if desired and add one or more annotations from the Tools menu. You can right-click on annotations to change their appearance to match your graph like I did. In upcoming posts, Xan and I will show how we created and optimized other favorite visualizations of my personal data that appeared on my poster.

      Check out the first blog in this series to learn more about my interest in quantified self (QS) data analysis and my JMP Discovery Summit 2014 e-poster that explored 1,316 days of my activity and food log data in JMP. You can use my JMP add-in to import your own BodyMedia® files. It’s free to join the JMP User Community, where you can learn from JMP users all over the world! In the videos section here, you can watch a video of Xan showing how to reproduce part of this graph during his "Unlocking the Power of Graph Builder" talk at JMP Discovery Summit 2014.

      Community Member

      Robert Allison wrote:

      I like the new/improved graph! :)

      Shannon Conners wrote:

      Thanks, Robert! I very much appreciated Xan's suggestions on this graph, and learned a lot from the tips and tricks he shared on how to create it.

      Community Member

      Sait COPUROGLU wrote:

      How is it possible to label the Carb, Fat, Alcohol, Protein beside their own lines/bars with the same color code? Is it an 12 spec? Missing it since I use JMP

      Shannon Conners wrote:

      Hi Sait, you can add annotations in JMP graphs by clicking on the Tools > Annotate menu or clicking on the graph toolbar icon that looks like a square with a capital T in the upper left corner. You're right, the default appearance of an Annotation doesn't match the graph line color. After I add an annotation box to my graph and add text to it, I right click on the annotation to uncheck the Filled option. This removes the colored background and black line, making the background white. Then, I right click on the annotation again and choose Font Color to change the color of the text to the same as the line in my graph. Annotations have been in JMP for many versions, but may not be fully supported for export in various formats. If you have specific questions about annotations, you can email me at Thanks!