Response: We can add supplementary elements such as linear trend lines and quadratic trend lines into the plots in R with the help of the ggplot2 package and its features. For example, let us consider airquality dataset and we want to draw a scatterplot between two parameters – wind and ozone as per below. ggplot(data = airquality,aes(x=Wind,y=Ozone))+geom_point()
We can use the geom_smooth() function and use the “lm” method to draw a linear trend line that is captured based on the current sample data. ggplot(data = airquality,aes(x=Wind,y=Ozone))+geom_point()+geom_smooth(method = "lm",se=TRUE)
Further, we can use a simple quadratic polynomial function to draw a quadratic trend line with the same dataset. ggplot(data = airquality,aes(x=Wind,y=Ozone))+geom_point()+geom_smooth(method = "lm",formula=y ~ poly(x,2), se=TRUE)