# Graph with errors from RDataFrame

**URL:** <https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [December 21, 2022, 4:10am UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841 "2022-12-21T04:10:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lilina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lilina/32/28468_2.png) [@lilina](https://root-forum.cern.ch/u/lilina)\
**Post date:** [December 21, 2022, 4:10am UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/1 "2022-12-21T04:10:14Z")

</div>

Hi!  
I am new using RDataFrame and I would like to clarify two questions:

1. Is there a way to get a graph with errors on the y-axis from a RDataFrame that contains x, y, and y-error in its columns? I have found examples with Graph but I would like to obtain a TGraphErrors for later fitting.
2. Can I retrieve the maximum range of the dataframe?

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [December 21, 2022, 7:57am UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/2 "2022-12-21T07:57:28Z")

</div>

Hi,  
I am myself a rather inexperienced user, but in the [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) Class reference is stated the function [GraphAsymmErrors](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#acea30792eef607489d498bf6547a00a6) which has asymmetric errors, but these could be set to the same value to obtain your wanted result. As for the maximum range, I am not sure, what you mean. There is a function [Max](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#aff59d655b068f76976cc7b3b40f4fff0) and [Min](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#acfa3df09a387ccb4973f34f4f0f64003) which could give you the range of your data.  
Hope this helps.  
Cheers,  
Emil

---

<div class="post-metadata">

**Author:** ![lilina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lilina/32/28468_2.png) [@lilina](https://root-forum.cern.ch/u/lilina)\
**Post date:** [December 21, 2022, 9:19pm UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/3 "2022-12-21T21:19:39Z")

</div>

Hi,  
Thank you so much for your reply and for letting me know about the GraphAsymmErrors. Do you know how can I make the errors on x (exl, exh) to be zero? I don’t have errors on the x-axis and I don’t have any column in the dataframe for them.

> [@Emil\_R](#):
>
> As for the maximum range, I am not sure, what you mean. There is a function [Max](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#aff59d655b068f76976cc7b3b40f4fff0) and [Min](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#acfa3df09a387ccb4973f34f4f0f64003) which could give you the range of your data.

I needed to get the total number of entries in the dataframe.  
Thanks a lot!!  
Lily

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [December 22, 2022, 7:25am UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/5 "2022-12-22T07:25:08Z")

</div>

It seems that there is a problem with TGraphAsymmErrors from RDataFrame; ROOT says `no member named 'GraphAsymmErrors' in 'ROOT::RDataFrame'`.  
Outside dataframe, you can just put zeroes where you want, e.g.

```auto
auto gr = new TGraphAsymmErrors(n,x,y,0,0,eyl,eyh);

```

but for RDataFrame the documentation says you should give a string (name of column), so if zero doesn’t work I suppose you could just use any column minus itself (e.g. `TGraphAsymmErrors("x","y","x-x","x-x","eyl","eyh")`), or define a column with that difference and use that column for zero errors.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [January 16, 2023, 4:32pm UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/6 "2023-01-16T16:32:11Z")

</div>

Hi,

I’m very late to the party, but just to clarify: GraphAsymmErrors is still unreleased: it’s present in the master branch (and therefore our nightly builds and it will be released with the upcoming ROOT v6.28.

In the meanwhile you might be able to emulate it by creating a `TGraphAsymmErrors` manually and passing it to RDataFrame’s `Fill` method.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![lilina](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lilina/32/28468_2.png) [@lilina](https://root-forum.cern.ch/u/lilina)\
**Post date:** [January 20, 2023, 5:11pm UTC](https://root-forum.cern.ch/t/graph-with-errors-from-rdataframe/52841/7 "2023-01-20T17:11:06Z")

</div>

Thanks Enrico,

I found an example here [ROOT: tutorials/dataframe/df005\_fillAnyObject.C File Reference](https://root.cern.ch/doc/master/df005__fillAnyObject_8C.html) on how to use the Fill method but I could not figure out how to use it on TGraphErrors since I don’t find this class to expose a `Fill` method. But following this post [Coloured scatterplot from TDataFrame - #2 by eguiraud](https://root-forum.cern.ch/t/coloured-scatterplot-from-tdataframe/26894/2) I could make the TGraphErrors from the dataframe:

```auto
TGraphErrors* gtrue;

auto fillTrueValuesGraph = [&gtrue](int set, double y, double err_y){
      gtrue->SetPoint(gtrue->GetN(), set, y);
      gtrue->SetPointError( gtrue->GetN()-1, 0, err_y );
   };

df.Foreach(fillTrueValuesGraph, {"set", "y", "err_y"});

```
