# Display a Fit equation on a plot?

**URL:** <https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874>\
**Category:** Questions\
**Tags:** graphics-and-visualization, statistics-and-probability\
**Created:** [July 22, 2018, 7:02pm UTC](https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874 "2018-07-22T19:02:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [July 22, 2018, 7:02pm UTC](https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874/1 "2018-07-22T19:02:31Z")

</div>

Hi,

Could you please let me know, how I can display fit equation and correlation coefficient value on plot?

Thanks for your help 🙂

```
data1 = {0, 1, 3, 5}

data2 = {1, 0, 2, 4}

R = Correlation[data1, data2] // N

data3 = Transpose@{data1, data2};

line = Fit[data, {1, x}, x]

Show[ListPlot[data, PlotStyle -> {PointSize@Large, Red}], 
 Plot[{line}, {x, 0, 5}]]

```

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 22, 2018, 8:40pm UTC](https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874/2 "2018-07-22T20:40:27Z")

</div>

You can use `Epilog`, or a `Graphics`:

```
Show[ListPlot[data, PlotStyle -> {PointSize@Large, Red}], 
 Plot[{line}, {x, 0, 5}], 
 Graphics[Text[Row[{"correlation = ", R}], Center]]]

```

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [July 22, 2018, 8:49pm UTC](https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874/3 "2018-07-22T20:49:35Z")

</div>

Maybe so:

```
 data1 = {0, 1, 3, 5};
 
 data2 = {1, 0, 2, 4};
 
 R = Correlation[data1, data2] // N;
 
 data3 = Transpose@{data1, data2};
 
 line = Fit[data3, {1, x}, x];

 Show[ListPlot[data3, PlotStyle -> {PointSize@Large, Red}], 
  Plot[Evaluate[line], {x, 0, 5}, PlotLabels -> "Expressions", 
   PlotLegends -> Placed["R=0.9022436", {8/10, 8/10}]], 
  PlotRange -> {{0, 8}, Automatic}]

```

 ![16991111.png](https://global.discourse-cdn.com/wolfram/original/3X/3/3/33bff091bea06a83ab0a25749eb8f0c7db938b57.png)

```
 Show[ListPlot[data3, PlotStyle -> {PointSize@Large, Red}], 
  Plot[Evaluate[line], {x, 0, 5}, 
   PlotLabels -> 
    Placed[{"y(x)=0.186440\[VeryThinSpace]+0.694915 x"}, {2, 3.5}], 
   PlotLegends -> Placed["R=0.9022436", {0.34, 7/10}]]]

```

 ![99262222.png](https://global.discourse-cdn.com/wolfram/original/3X/7/1/71b6cc64124dc034bce56c4085b4329acade13f5.png)

---

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [July 23, 2018, 9:03pm UTC](https://community.wolfram.com/t/display-a-fit-equation-on-a-plot/12874/4 "2018-07-23T21:03:29Z")

</div>

Dear Gianluca and Mariusz,

Thank so much for your useful response.

Regards,
