Message Boards Message Boards

Unable to plot dataset with ErrorListPlot and Style

I am trying to make list plots with the ErrorListPlot function. I have two datasets (ds1 and ds2) of which one plots nicely (ds1) and the other just give blank plots. I cannot see any difference in the way the datasets are set up so I am puzzled about why there should be any difference between them. I get no error message.

Here is my code:

Needs["ErrorBarPlots`"]
ds1 = Dataset[{
<|"Sample" -> 1, "variable" -> "variable1", "mean" -> 1.`, 
 "min" -> 0.7662`, "max" -> 1.3051`|>, <|"Sample" -> 1, 
 "variable" -> "variable2", "mean" -> 0.0202`, "min" -> 0.011`, 
 "max" -> 0.0371`|>, <|"Sample" -> 1, "variable" -> "variable3", 
 "mean" -> 0.0001`, "min" -> 0.0001`, 
 "max" -> 0.0002`|>, <|"Sample" -> 2, "variable" -> "variable1", 
 "mean" -> 1.`, "min" -> 0.9368`, 
 "max" -> 1.0674`|>, <|"Sample" -> 2, "variable" -> "variable2", 
 "mean" -> 0.0511`, "min" -> 0.0431`, 
 "max" -> 0.0606`|>, <|"Sample" -> 2, "variable" -> "variable3", 
 "mean" -> 0.0001`, "min" -> 0.`, 
 "max" -> 0.0001`|>, <|"Sample" -> 3, "variable" -> "variable1", 
 "mean" -> 1.`, "min" -> 0.665`, 
 "max" -> 1.5038`|>, <|"Sample" -> 3, "variable" -> "variable2", 
 "mean" -> Missing["NA"], "min" -> Missing["NA"], 
 "max" -> Missing["NA"]|>, <|"Sample" -> 3, 
 "variable" -> "variable3", "mean" -> 0.2117`, "min" -> 0.1521`, 
 "max" -> 0.2947`|>}];

ds2 = Dataset[
{<|"Sample" -> 1, "variable" -> "variable1", "mean" -> 1.`, 
 "min" -> 0.8506`, "max" -> 1.1756`|>, <|"Sample" -> 1, 
 "variable" -> "variable2", "mean" -> 0.0277`, "min" -> 0.0196`, 
 "max" -> 0.0392`|>, <|"Sample" -> 1, "variable" -> "variable3", 
 "mean" -> 0.0001`, "min" -> 0.`, 
 "max" -> 0.0002`|>, <|"Sample" -> 2, "variable" -> "variable1", 
 "mean" -> 1.`, "min" -> 0.3085`, 
 "max" -> 3.2415`|>, <|"Sample" -> 2, "variable" -> "variable2", 
 "mean" -> 0.0326`, "min" -> 0.0127`, 
 "max" -> 0.0836`|>, <|"Sample" -> 2, "variable" -> "variable3", 
 "mean" -> 0.`, "min" -> 0.`, "max" -> 0.0002`|>, <|"Sample" -> 3,
  "variable" -> "variable1", "mean" -> 1.`, "min" -> 0.6651`, 
 "max" -> 1.5034`|>, <|"Sample" -> 3, "variable" -> "variable2", 
 "mean" -> 0.0164`, "min" -> 0.0112`, 
 "max" -> 0.024`|>, <|"Sample" -> 3, "variable" -> "variable3", 
 "mean" -> 0.0001`, "min" -> 0.`, 
 "max" -> 0.0002`|>, <|"Sample" -> 4, "variable" -> "variable1", 
 "mean" -> 1.`, "min" -> 0.4146`, 
 "max" -> 2.412`|>, <|"Sample" -> 4, "variable" -> "variable2", 
 "mean" -> 0.0437`, "min" -> 0.0222`, 
 "max" -> 0.0858`|>, <|"Sample" -> 4, "variable" -> "variable3", 
 "mean" -> 0.0057`, "min" -> 0.0017`, 
 "max" -> 0.0188`|>, <|"Sample" -> 5, "variable" -> "variable1", 
 "mean" -> 1.`, "min" -> 0.768`, 
 "max" -> 1.302`|>, <|"Sample" -> 5, "variable" -> "variable2", 
 "mean" -> 0.0261`, "min" -> 0.02`, 
 "max" -> 0.0339`|>, <|"Sample" -> 5, "variable" -> "variable3", 
 "mean" -> 0.`, "min" -> 0.`, "max" -> 0.`|>, <|"Sample" -> 6, 
 "variable" -> "variable1", "mean" -> 1.`, "min" -> 0.6516`, 
 "max" -> 1.5348`|>, <|"Sample" -> 6, "variable" -> "variable2", 
 "mean" -> Missing["NA"], "min" -> Missing["NA"], 
 "max" -> Missing["NA"]|>, <|"Sample" -> 6, 
 "variable" -> "variable3", "mean" -> 0.317`, "min" -> 0.23`, 
 "max" -> 0.4369`|>}];

varList = DeleteDuplicates[ds1[All, "variable"]] // Normal;

ds1[GroupBy[#variable &], 
  ErrorListPlot[
    Style[{{#, #2}, ErrorBar[{-(# - #3), (#4 - #)}, 0]}] & @@@ #, 
    Frame -> True,
    PlotTheme -> "Scientific", 
    PlotStyle -> {Black, PointSize[.015]}] &,
  {"mean", "Sample", "min", "max"}] /@ varList

And this is the results:

Dataset 1: I get one plot like this for each sample, displaying points with error-bars.

enter image description here

Dataset2: I get one plot like this for each sample, displaying blank grids.

enter image description here

Does anyone have any idea on what is going on with dataset 2? Thanks!

POSTED BY: audun bersaas
2 Replies

It's very helpful to break your code down and provide a minimal example of the problem. If a plot isn't working, then look at how the plotting function is being called in a specific case. We'll use variable1 of dataset2. In this case, take a look at the code given to ErrorListPlot:

ErrorListPlot[
    {Style[{{1., 1}, ErrorBar[{-0.14939999999999998, 0.17559999999999998}, 0]}], 
     Style[{{1., 2}, ErrorBar[{-0.6915, 2.2415}, 0]}], 
     Style[{{1., 3}, ErrorBar[{-0.3349, 0.5034000000000001}, 0]}], 
     Style[{{1., 4}, ErrorBar[{-0.5853999999999999, 1.412}, 0]}], 
     Style[{{1., 5}, ErrorBar[{-0.23199999999999998, 0.30200000000000005}, 0]}], 
     Style[{{1., 6}, ErrorBar[{-0.34840000000000004, 0.5347999999999999}, 0]}]}
]

Your data is wrapped in Style. Style doesn't seem to be doing anything. If you get rid of it, ErrorListPlot works fine.

Replace

Style[{{#, #2}, ErrorBar[{-(# - #3), (#4 - #)}, 0]}]

With

{{#, #2}, ErrorBar[{-(# - #3), (#4 - #)}, 0]}

The documentation for ErrorListPlot doesn't show that it accepts input wrapped in Style. It seems to work fine with three inputs and break with six. The fact that it worked with three inputs appears to be a "lucky" fluke. In general you can't use Style with this function.

POSTED BY: Sean Clarke

Thank you for your help! That solves my problem.

POSTED BY: audun bersaas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract