- Related Questions & Answers
- How to join points in a point chart with lines using ggplot2 in R?
- How to create a scatterplot in base R with points depending on categorical column?
- How to create a scatterplot in R using ggplot2 with transparency of points?
- How to put labels on a scatterplot that is created plot function in R?
- How to create a scatterplot in R using ggplot2 with different designs of points?
- How to write the plot title in multiple lines using plot function in R?
- How to create two vertical lines on a plot with shaded area in-between using R?
- How to create a plot in R with gridlines using plot function?
- How to create a scatterplot using ggplot2 with different shape and color of points based on a variable in R?
- How to increase the size of points on a scatterplot if the points are drawn based on another sequence using ggplot2 in R?
- How to change the color of points in a scatterplot using ggplot2 in R?
- How to represent the legend in a plot created by using plot function with colored straight lines or stars in R?
- How to create a plot in R with a different plot window size using plot function?
- How to create a scatterplot with colors of the group of points in R?
- How to create a scatterplot in R with legend position inside the plot area using ggplot2?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

It is very difficult to join points on a scatterplot with smooth lines if the scatteredness is high but we might want to look at the smoothness that cannot be understood by just looking at the points. It is also helpful to understand whether the model is linear or not. We can do this by plotting the model with loess using plot function.

Consider the below data −

> set.seed(3) > x<-sample(1:100,10,replace=TRUE) > y<-rpois(10,100)

Using loess to create the smooth lines −

> Model <- loess(y~x) > summary(Model) Call: loess(formula = y ~ x) Number of Observations: 10 Equivalent Number of Parameters: 4.77 Residual Standard Error: 8.608 Trace of smoother matrix: 5.27 (exact) Control settings: span : 0.75 degree : 2 family : gaussian surface : interpolate cell = 0.2 normalize : TRUE parametric : FALSE drop.square: FALSE > plot(x,y)

> lines(Model, col='red', lwd=2)

Advertisements