Vindaar / ggplotnim

A port of ggplot2 for Nim
https://vindaar.github.io/ggplotnim
MIT License
177 stars 15 forks source link

`geom_errorbar` can produce bad plots #94

Closed Vindaar closed 3 years ago

Vindaar commented 3 years ago

The following code produces a broken error bar plot on my machine right now:

  var angles = newSeq[int]()
  var data = newSeq[int]()
  var err = newSeq[float]()
  let toUse = if input.len == 0: Data4 else: readDataFile(input)

  for k, v in tab:
    angles.add v
    data.add toUse[k]
    err.add sqrt(toUse[k].float)

  let df = seqsToDf({ "Angles" : angles,
                      "Counts" : data,
                      "Error" : err})
    .mutate(fn {"yMin" ~ `Counts` - `Error`},
            fn {"yMax" ~ `Counts` + `Error`},
            fn {"xMin" ~ `Angles` - 7.5},
            fn {"xMax" ~ `Angles` + 7.5})
  echo df
  ggplot(df, aes("Angles", "Counts")) +
    geom_point() +
    geom_errorbar(aes = aes(xMin = xMin,
                            xMax = xMax)) +
    geom_errorbar(aes = aes(yMin = yMin,
                            yMax = yMax)) +
    ggsave("plots/angular.pdf")

The resulting plot:

angular

Another other issue is:

If I do both x and y min/max aesthetic selections in one errorbar call, then the x errors are missing completely!

Vindaar commented 2 years ago

https://github.com/Vindaar/ginger/pull/40 will fix a similar bug for the x axis when using xMargin.