#fit a linear regression model to the data
#Vertical line spss code how to
The following code illustrates how to add a fitted linear regression line to a scatterplot: #define dataset The basic code to add a simple linear regression line to a plot in R is: abline(model) #draw a vertical dashed line at the mean value #create dataset with 1000 random values normally distributed with mean = 10, sd = 2 The following code illustrates how to add a vertical line at the mean value on a histogram: #make this example reproducible The basic code to add a vertical line to a plot in R is: abline(v = some value) #create horizontal lines at one standard deviation above and below the mean valueĪbline(h = mean(data$y) + sd(data$y), col = 'steelblue', lwd = 3, lty = 2)Ībline(h = mean(data$y) - sd(data$y), col = 'steelblue', lwd = 3, lty = 2) #create horizontal line at mean value of yabline(h = mean(data$y), lwd = 2) The following code illustrates how to add a horizontal solid line at the mean value of y along with two horizontal dashed lines at one standard deviation above and below the mean value: #create scatterplot for x and y To add a horizontal line at the value y = 20, we can use the following code: abline(h = 20, col = 'coral2', lwd = 2) Suppose we have the following scatterplot that displays the values for x and y in a dataset: #define datasetĭata <- ame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11), The basic code to add a horizontal line to a plot in R is: abline(h = some value)
The following examples show how to use this function in practice.