Graphics, Figures & Tablespgfplots : How to add a linear regression line?

Information and discussion about graphics, figures & tables in LaTeX documents.
Masruk
Posts: 1
Joined: Wed May 16, 2018 4:28 pm

pgfplots : How to add a linear regression line?

Post by Masruk »

mas wrote:
1. How to modify the code above to add a linear regression line, with options for its style (color and thickness)?
Just add another addplot command:

Code: Select all

\addplot+[no marks,red, thick] {1.2304 * x + 0.5121 } ;
2. How to show its equation (with many digits)? and to change its "X" and "Y" symbols? (so the equation is using exactly the same symbols as on the axis).
The usual tikz node command should do the trick.

Code: Select all

\node at (1.5,0) {$Y=1.2304 X + 0.5121} ;

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply