I have a DataSet that contains records with:

  • an "activityName" string representing the kind of activity
  • a "duration" value representing minutes
  • a DateObject representing a date and time named "startTime"

I can access the records in the DataSet with this code:

myDataSet[All, {"activityName", "duration", "startTime"}]

I can plot all the records with this code:

DateListPlot[myDataSet[All, {"startTime", "duration"}] // Values  // Normal

But what I want to do is identify in the graph the different activities such that each activity is rendered in a different line / points, along the lines of this sort of output:

Multi-category chart

Note that the data across the various activities is not consistent nor is it supposed to be.

It would be ideal to leverage the dynamic capabilities of the language so that the user can see all the data overlaid and then select the (multiple) activities of interest to look only at those data.


1 Answer 1


You may use GroupBy in Dataset's Query syntax.

For individual plots per activity.

res1 = myDataSet[GroupBy["activityName"], DateListPlot, {"startTime", "duration"}]

Mathematica graphics

With individual plots accessed by activity name.


Mathematica graphics

For one combined plot the position of DateListPlot needs to move up one level in the hierarchy.

 GroupBy["activityName"] /* DateListPlot, 
 {"startTime", "duration"}

Mathematica graphics

Hope this helps.

  • $\begingroup$ Thanks a lot for this, Edmund. I see what you are doing with the GroupBy and this makes sense. However, I'm not familiar with the "/* operator which appears to pass the output to the next function. I looked for this operator but have not been able to find it in the documentation. Also, I would like to do more customisation to the DateListPlot, so it would be nice to call it alone. I tried assigning the GroupBy to a variable and passing that to DateListPlot and got an error saying: Message: Part {startTime, duration} is not applicable to expressions of the form {__Association}. $\endgroup$ Commented Dec 8, 2018 at 11:25
  • $\begingroup$ @BartonFriedland I'm on my phone so a bit limited but look up RightComposition in the documentation. Also, you must make a pure function of DateListPlot. For example, (DateListPlot[#, Filling -> Axis]&). The brackets are import to isolate the pure function within RightComposition. Will update when I'm back at my computer. $\endgroup$
    – Edmund
    Commented Dec 8, 2018 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.