contour() 等高线图
(2016-06-08 09:05:38)| 标签: r语言contour()等高线图 | 分类: R语言学习 | 
| contour {graphics} | R Documentation | 
Display Contours
Description
Create a contour plot, or add contour lines to an existing plot.
Usage
contour(x, ...)
## Default S3 method:
contour(x = seq(0, 1, length.out = nrow(z)),
        y = seq(0, 1, length.out = ncol(z)),
        z,
        nlevels = 10, levels = pretty(zlim, nlevels),
        labels = NULL,
        xlim = range(x, finite = TRUE),
        ylim = range(y, finite = TRUE),
        zlim = range(z, finite = TRUE),
        labcex = 0.6, drawlabels = TRUE, method = "flattest",
        vfont, axes = TRUE, frame.plot = axes,
        col = par("fg"), lty = par("lty"), lwd = par("lwd"),
        add = FALSE, ...)
Arguments
| x,
y | 数值向量,设置网格线的位置与矩阵z中值的对应关系. | 
| z | 用于画图的数值向量. | 
| nlevels | 登高水平的数量,(只有在设置了levels的情况下才有效) | 
| levels | 数值向量,设置画线的位置. | 
| labels | 等高线标签. | 
| labcex | 
 | 
| drawlabels | 逻辑值,是否要画等高标签. | 
| method | 字符,设置画等高标签的位置. | 
| vfont | 两个元素组成的字符向量,设置等高标签的字体。. | 
| xlim | x轴的范围,ylim 为y轴的范围,zlim为z轴的范围. | 
| axes | 逻辑值,是否要画坐标轴;frame.plot是否要在图外围画上框线 | 
| col | 等高线的颜色. | 
| lty | 线的类型. | 
| lwd | 线的宽度. | 
| add | 逻辑值,是否要将等高线添加到已有的图上. | 
| ... | 其他传递给函数的参数. | 
 
See Also
options("max.contour.segments") 
contourLines, filled.contour contourplot levelplot)
from package image demo(graphics).
Examples
require(grDevices) # for colours
x <- -6:16
op <- par(mfrow = c(2, 2))
contour(outer(x, x), method = "edge", vfont = c("sans serif", "plain"))
z <- outer(x, sqrt(abs(x)), FUN = "/")
image(x, x, z)
contour(x, x, z, col = "pink", add = TRUE, method = "edge",
        vfont = c("sans serif", "plain"))
contour(x, x, z, ylim = c(1, 6), method = "simple", labcex = 1,
        xlab = quote(x[1]), ylab = quote(x[2]))
contour(x, x, z, ylim = c(-6, 6), nlev = 20, lty = 2, method = "simple",
        main = "20 levels; \"simple\" labelling method")
par(op)
## Persian Rug Art:
x <- y <- seq(-4*pi, 4*pi, len = 27)
r <- sqrt(outer(x^2, y^2, "+"))
opar <- par(mfrow = c(2, 2), mar = rep(0, 4))
for(f in pi^(0:3))
  contour(cos(r^2)*exp(-r/f),
          drawlabels = FALSE, axes = FALSE, frame = TRUE)
rx <- range(x <- 10*1:nrow(volcano))
ry <- range(y <- 10*1:ncol(volcano))
ry <- ry + c(-1, 1) * (diff(rx) - diff(ry))/2
tcol <- terrain.colors(12)
par(opar); opar <- par(pty = "s", bg = "lightcyan")
plot(x = 0, y = 0, type = "n", xlim = rx, ylim = ry, xlab = "", ylab = "")
u <- par("usr")
rect(u[1], u[3], u[2], u[4], col = tcol[8], border = "red")
contour(x, y, volcano, col = tcol[2], lty = "solid", add = TRUE,
        vfont = c("sans serif", "plain"))
title("A Topographic Map of Maunga Whau", font = 4)
abline(h = 200*0:4, v = 200*0:4, col = "lightgray", lty = 2, lwd = 0.1)
## contourLines produces the same contour lines as contour
plot(x = 0, y = 0, type = "n", xlim = rx, ylim = ry, xlab = "", ylab = "")
u <- par("usr")
rect(u[1], u[3], u[2], u[4], col = tcol[8], border = "red")
contour(x, y, volcano, col = tcol[1], lty = "solid", add = TRUE,
        vfont = c("sans serif", "plain"))
line.list <- contourLines(x, y, volcano)
invisible(lapply(line.list, lines, lwd=3, col=adjustcolor(2, .3)))
par(opar)
							
		
 加载中…
加载中…