Add a Statistical Layer on Line Chart in ggplot2

Premium

R has become very popular not just because of its data visualization capabilities but also its ability to combine data visualizations with statistical information. The statistics layer helps us represent statistical information about the data, such as mean and variance, to help in understanding the data.

We earlier learned about geoms which stand for "geometric objects." These are the core elements that you see on the plot, and includes objects such as points, lines, areas, and curves. Stats stand for "statistical transformations." These help us summarize the data in different ways such as counting observations, creating a linear regression line that best fits the data, or adding a confidence interval to the regression line.

Unlock Premium Content

Upgrade your account to access the full article, downloads, and exercises.

You'll get access to:

  • Access complete tutorials and examples
  • Download source code and resources
  • Follow along with practical exercises
  • Get in-depth explanations

Course Downloads

eBook - Data Visualization with R

eBook for Data Visualization with R

PDF
Premium
Upgrade to Pro

Data and R Code

Data and R Code Files for Data Visualization with R

ZIP
Premium
Upgrade to Pro