在R中绘制两条线,斜率是最佳拟合线的两倍和一半的值

D W*_*D W 1 plot r linear-regression

我有最适合的线条绘制数据.我需要绘制另外两行.一个需要有两倍的斜率,另一个需要有一半的斜率.稍后我将使用该区域对其外部的点进行差分着色: 有条件地将颜色数据点放在R中的置信区间之外

示例数据集:

## Dataset from http://www.apsnet.org/education/advancedplantpath/topics/RModules/doc1/04_Linear_regression.html

## Disease severity as a function of temperature

# Response variable, disease severity
diseasesev<-c(1.9,3.1,3.3,4.8,5.3,6.1,6.4,7.6,9.8,12.4)

# Predictor variable, (Centigrade)
temperature<-c(2,1,5,5,20,20,23,10,30,25)

## For convenience, the data may be formatted into a dataframe
severity <- as.data.frame(cbind(diseasesev,temperature))

## Fit a linear model for the data and summarize the output from function lm()
severity.lm <- lm(diseasesev~temperature,data=severity)

# Take a look at the data
plot(
  diseasesev~temperature,
  data=severity,
  xlab="Temperature",
  ylab="% Disease Severity",
  pch=16,
  pty="s",
  xlim=c(0,30),
  ylim=c(0,30)
)
title(main="Graph of % Disease Severity vs Temperature")
par(new=TRUE) # don't start a new plot
abline(severity.lm, col="blue")
Run Code Online (Sandbox Code Playgroud)

nic*_*ico 5

你可以使用

# This gets the coefficients of the linear regression (intercept and slope)
c <- coef(severity.lm)
abline(c[1], c[2]*2, col="red")
abline(c[1], c[2]/2, col="red")
Run Code Online (Sandbox Code Playgroud)