Question: How to add a smoother to a scatterplot in ggpubr?"

A smoother line is a line that is fitted to the data that helps you explore the potential relationships between two variables without fitting a specific model, such as a regression line or a theoretical distribution. Smoother lines are most useful when the curvature of the relationship does not change sharply. Data smoothing can then help to identify simplified changes in order to help predict different trends and patterns.

We’ll use the “palmerpenguins” package for this example

#Data

## Loading required package: ggplot2

Making a scatterplot

ggscatter(x="flipper_length_mm",
          y="bill_length_mm",
          data=penguins)
## Warning: Removed 2 rows containing missing values (geom_point).

Add smoother using the “add = loess” argument

Loess stands for Locally Weighted Scatterplot Smoothing. It is also called ‘weighted smoothing’.

ggscatter(x="flipper_length_mm",
          y="bill_length_mm",
          add  = "loess",  # data smoother
          data=penguins)
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

# Additional Reading

https://www.statisticshowto.com/lowess-smoothing/

Keywords

  1. scatter plot
  2. ggscatter()
  3. smoother
  4. loess
  5. correlations