Here are some scatter plot examples using R
A straightforward scatter diagram with a regression line:
R
# Generate random data x <- rnorm (100) y <- 2*x + rnorm (100) # Create scatter plot with regression line plot (x, y) abline ( lm (y ~ x)) |
The first two lines of the code produce randomly distributed data for x and y. With x on the horizontal axis and y on the vertical axis, the third line generates a scatter diagram. The fourth line adds a regression line to the picture by fitting a linear regression model of y on x using the abline() and lm() functions. The resulting plot illustrates the relationship between x and y, with the regression line pointing in the right direction and showing how strongly the two variables are correlated.
Contact Us