R語言
grid
位於 graphics
包(package)。 說明
grid
將 nx
和 ny
矩形網格添加到現有繪圖中。
用法
grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted",
lwd = par("lwd"), equilogs = TRUE)
參數
nx , ny |
x 和 y 方向上網格的單元數。當 |
col |
字符或(整數)數字;網格線的顏色。 |
lty |
字符或(整數)數字;網格線的線型。 |
lwd |
給出網格線寬度的非負數字。 |
equilogs |
邏輯,僅當日誌坐標和與軸刻度線的對齊處於活動狀態時使用。在這種情況下設置 |
注意
如果需要更精細的調整,請直接使用abline(h = ., v = .)
。
例子
plot(1:3)
grid(NA, 5, lwd = 2) # grid only in y-direction
## maybe change the desired number of tick marks: par(lab = c(mx, my, 7))
op <- par(mfcol = 1:2)
with(iris,
{
plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
xlim = c(4, 8), ylim = c(2, 4.5), panel.first = grid(),
main = "with(iris, plot(...., panel.first = grid(), ..) )")
plot(Sepal.Length, Sepal.Width, col = as.integer(Species),
panel.first = grid(3, lty = 1, lwd = 2),
main = "... panel.first = grid(3, lty = 1, lwd = 2), ..")
}
)
par(op)
plot(1:64)
gr <- grid() # now *invisibly* returns the grid "at" locations
str(gr)
stopifnot(length(gr) == 2, identical(gr[[1]], gr[[2]]),
gr[["atx"]] == 10*(0:6))
## In log-scale plots :
plot(8:270, log="xy") ; grid() # at (1, 10, 100); if preferring "all" grid lines:
plot(8:270, log="xy") ; grid(equilogs = FALSE) -> grll
stopifnot(identical(grll, list(atx = c(1, 2, 5, 10, 20, 50, 100, 200),
aty = c( 10, 20, 50, 100, 200))))
參考
Murrell, P. (2005) R Graphics. Chapman & Hall/CRC Press.
也可以看看
相關用法
- R legend 將圖例添加到繪圖中
- R barplot 條形圖
- R plot.histogram 繪製直方圖
- R points 向繪圖添加點
- R stem 莖葉圖
- R mtext 將文本寫入繪圖的邊距
- R arrows 將箭頭添加到繪圖中
- R contour 顯示輪廓
- R pairs 散點圖矩陣
- R stars 星圖(蜘蛛圖/雷達圖)和線段圖
- R box 在地塊周圍畫一個方框
- R coplot 調節圖
- R smoothScatter 具有平滑密度顏色表示的散點圖
- R mosaicplot 馬賽克圖
- R bxp 從摘要中繪製箱線圖
- R plot.raster 繪製光柵圖像
- R axTicks 計算軸刻度線位置
- R curve 繪製函數圖
- R plot.factor 繪製因子變量
- R sunflowerplot 製作向日葵散點圖
- R plot.table 表對象的繪圖方法
- R units 圖形單位
- R identify 識別散點圖中的點
- R layout 指定複雜的繪圖安排
- R polygon 多邊形繪製
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Add Grid to a Plot。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。