A smoother is a data exploration tool which helps you visualize trends in the data. How do you add a smoother to scatterplot?
We’ll use the “palmerpenguins” packages (https://allisonhorst.github.io/palmerpenguins/) to address this question. You’ll need to install the package with install.packages(“palmerpenguins”) if you have not done so before, call library("“palmerpenguins”), and load the data with data(penguins)
#install.packages("palmerpenguins")
library(ggpubr)
## Loading required package: ggplot2
library(palmerpenguins)
## Warning: package 'palmerpenguins' was built under R version 4.1.2
data(penguins)
We make scatterplots in R with the ggscatter() function. One single type of smoother is a loess smoother, you can add it witht the “add” parameter in ggscatter()
ggscatter(x="body_mass_g",y="bill_length_mm",
add = "loess",
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).
For more information on this topic, see https://www.datanovia.com/en/blog/how-to-plot-a-smooth-line-using-ggplot2/
1.ggpubr 2.ggplot2 3.add 4.ggscatter() 5.palmerpenguins