abline
位於 graphics
包(package)。 說明
此函數在當前繪圖中添加一條或多條直線。
用法
abline(a = NULL, b = NULL, h = NULL, v = NULL, reg = NULL,
coef = NULL, untf = FALSE, ...)
參數
a, b |
截距和斜率,單一值。 |
untf |
合乎邏輯地詢問是否取消轉換。查看具體信息'。 |
h |
y-value(s) 表示水平線。 |
v |
x-value(s) 表示垂直線。 |
coef |
長度為 2 的向量,給出截距和斜率。 |
reg |
具有 |
... |
graphical parameters 例如 |
細節
典型用法是
abline(a, b, ...) abline(h =, ...) abline(v =, ...) abline(coef =, ...) abline(reg =, ...)
第一種形式以截距/斜率形式指定直線(或者 a
可以單獨指定,並用於包含矢量形式的斜率和截距)。
h=
和v=
表單在指定坐標處繪製水平和垂直線。
coef
形式通過包含斜率和截距的向量指定直線。
reg
是具有 coef
方法的回歸對象。如果返回長度為 1 的向量,則該值將被視為通過原點的直線的斜率,否則,前 2 個值將被視為截距和斜率。
如果untf
為true,並且一個或兩個軸都是log-transformed,則繪製一條與原始坐標係中的直線相對應的曲線,否則在變換後的坐標係中繪製一條直線。 h
和v
參數始終引用原始坐標。
可以指定graphical parameters、col
、lty
和lwd
;有關詳細信息,請參閱par
。對於 h=
和 v=
用法,它們可以是長度大於 1 的向量,並根據需要回收。
指定用於剪切的 xpd
參數將覆蓋否則使用的全局 par("xpd")
設置。
例子
## Setup up coordinate system (with x == y aspect ratio):
plot(c(-2,3), c(-1,5), type = "n", xlab = "x", ylab = "y", asp = 1)
## the x- and y-axis, and an integer grid
abline(h = 0, v = 0, col = "gray60")
text(1,0, "abline( h = 0 )", col = "gray60", adj = c(0, -.1))
abline(h = -1:5, v = -2:3, col = "lightgray", lty = 3)
abline(a = 1, b = 2, col = 2)
text(1,3, "abline( 1, 2 )", col = 2, adj = c(-.1, -.1))
## Simple Regression Lines:
require(stats)
sale5 <- c(6, 4, 9, 7, 6, 12, 8, 10, 9, 13)
plot(sale5)
abline(lsfit(1:10, sale5))
abline(lsfit(1:10, sale5, intercept = FALSE), col = 4) # less fitting
z <- lm(dist ~ speed, data = cars)
plot(cars)
abline(z) # equivalent to abline(reg = z) or
abline(coef = coef(z))
## trivial intercept model
abline(mC <- lm(dist ~ 1, data = cars)) ## the same as
abline(a = coef(mC), b = 0, col = "blue")
參考
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Murrell, P. (2005) R Graphics. Chapman & Hall/CRC Press.
也可以看看
相關用法
- R arrows 將箭頭添加到繪圖中
- R axTicks 計算軸刻度線位置
- R axis 將軸添加到繪圖中
- R assocplot 關聯圖
- R axis.POSIXct 日期和日期時間繪圖函數
- R legend 將圖例添加到繪圖中
- R barplot 條形圖
- R plot.histogram 繪製直方圖
- R points 向繪圖添加點
- R stem 莖葉圖
- R mtext 將文本寫入繪圖的邊距
- R contour 顯示輪廓
- R pairs 散點圖矩陣
- R stars 星圖(蜘蛛圖/雷達圖)和線段圖
- R box 在地塊周圍畫一個方框
- R coplot 調節圖
- R smoothScatter 具有平滑密度顏色表示的散點圖
- R mosaicplot 馬賽克圖
- R bxp 從摘要中繪製箱線圖
- R plot.raster 繪製光柵圖像
- R curve 繪製函數圖
- R plot.factor 繪製因子變量
- R sunflowerplot 製作向日葵散點圖
- R plot.table 表對象的繪圖方法
- R units 圖形單位
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Add Straight Lines to a Plot。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。