persp(graphics)
persp()所属R语言包:graphics
Perspective Plots
透视图解
译者:生物统计家园网 机器人LoveR
描述----------Description----------
This function draws perspective plots of a surface over the x–y plane. persp is a generic function.
此功能在X-Y平面的表面绘制的透视图。 persp是一个通用的功能。
用法----------Usage----------
persp(x, ...)
## Default S3 method:[默认方法]
persp(x = seq(0, 1, length.out = nrow(z)),
y = seq(0, 1, length.out = ncol(z)),
z, xlim = range(x), ylim = range(y),
zlim = range(z, na.rm = TRUE),
xlab = NULL, ylab = NULL, zlab = NULL,
main = NULL, sub = NULL,
theta = 0, phi = 15, r = sqrt(3), d = 1,
scale = TRUE, expand = 1,
col = "white", border = NULL, ltheta = -135, lphi = 0,
shade = NA, box = TRUE, axes = TRUE, nticks = 5,
ticktype = "simple", ...)
参数----------Arguments----------
参数:x, y
locations of grid lines at which the values in z are measured. These must be in ascending order. By default, equally spaced values from 0 to 1 are used. If x is a list, its components x$x and x$y are used for x and y, respectively.
在网格线的位置中的值z测量。这些必须是升序。默认情况下,使用等距值从0到1。如果x是list,其成分x$x和x$y是用于x和y,分别。
参数:z
a matrix containing the values to be plotted (NAs are allowed). Note that x can be used instead of z for convenience.
矩阵包含值绘制(NA的允许)。注意x可以用来代替z为了方便。
参数:xlim, ylim, zlim
x-, y- and z-limits. These should be chosen to cover the range of values of the surface: see "Details".
X,Y,Z-极限。这些应选择覆盖面值的范围:见“详细资料”。
参数:xlab, ylab, zlab
titles for the axes. N.B. These must be character strings; expressions are not accepted. Numbers will be coerced to character strings.
对轴的标题。注:这些都必须是字符串表达式不接受。号码将被强制转换为字符串。
参数:main, sub
main and sub title, as for title.
主,次标题,作为title。
参数:theta, phi
angles defining the viewing direction. theta gives the azimuthal direction and phi the colatitude.
角度定义观察方向。 theta给人的方位角方向和phi余纬。
参数:r
the distance of the eyepoint from the centre of the plotting box.
从绘图框的中心距离的视点。
参数:d
a value which can be used to vary the strength of the perspective transformation. Values of d greater than 1 will lessen the perspective effect and values less and 1 will exaggerate it.
一个可以用不同的透视变换的强度值。值d大于1,将减少的透视效果和值少1会夸大它。
参数:scale
before viewing the x, y and z coordinates of the points defining the surface are transformed to the interval [0,1]. If scale is TRUE the x, y and z coordinates are transformed separately. If scale is FALSE the coordinates are scaled so that aspect ratios are retained. This is useful for rendering things like DEM information.
之前观看的x,y和z坐标点确定表面转化为区间[0,1]。如果scale是TRUEX,Y和Z坐标转换分开。 scale如果是FALSE坐标宽高比缩放,以便保留。“呈现像数字高程模型信息的东西,这是非常有用的。
参数:expand
a expansion factor applied to the z coordinates. Often used with 0 < expand < 1 to shrink the plotting box in the z direction.
A扩展因子应用到z坐标。经常使用0 < expand < 1z方向缩小绘图框。
参数:col
the color(s) of the surface facets. Transparent colours are ignored. This is recycled to the (nx-1)(ny-1) facets.
表面面的颜色(S)。透明色被忽略。这是回收(nx-1)(ny-1)方面。
参数:border
the color of the line drawn around the surface facets. The default, NULL, corresponds to par("fg"). A value of NA will disable the drawing of borders: this is sometimes useful when the surface is shaded.
周围绘制表面面线的颜色。默认情况下,NULL,对应par("fg")。一个值NA“将关闭边界的图:这有时是有益的,当表面被阴影。
参数:ltheta, lphi
if finite values are specified for ltheta and lphi, the surface is shaded as though it was being illuminated from the direction specified by azimuth ltheta and colatitude lphi.
如果被指定为有限值ltheta和lphi,表面阴影,虽然它被从由方位角ltheta和余纬lphi指定的方向照亮。
参数:shade
the shade at a surface facet is computed as ((1+d)/2)^shade, where d is the dot product of a unit vector normal to the facet and a unit vector in the direction of a light source. Values of shade close to one yield shading similar to a point light source model and values close to zero produce no shading. Values in the range 0.5 to 0.75 provide an approximation to daylight illumination.
表面面的阴影计算((1+d)/2)^shade,其中d是正常的面和光源方向的单位向量的单位向量的点积。值shade接近产量遮光类似点光源模型和数值接近为零,不产生阴影。 0.5至0.75的范围值提供了一个近似日光照明。
参数:box
should the bounding box for the surface be displayed. The default is TRUE.
应显示为表面的边界框。默认TRUE。
参数:axes
should ticks and labels be added to the box. The default is TRUE. If box is FALSE then no ticks or labels are drawn.
刻度线和标签应该被添加到箱子。默认TRUE。 box如果是FALSE没有刻度线或标签绘制。
参数:ticktype
character: "simple" draws just an arrow parallel to the axis to indicate direction of increase; "detailed" draws normal ticks as per 2D plots.
字符"simple"提请只是一个箭头平行轴,表明增加的方向;"detailed"每2D绘图绘制正常刻度线。
参数:nticks
the (approximate) number of tick marks to draw on the axes. Has no effect if ticktype is "simple".
刻度线(近似),标志着绘制轴。没有效果ticktype如果是"simple"。
参数:...
additional graphical parameters (see par).
额外的图形参数(见par)。
Details
详情----------Details----------
The plots are produced by first transforming the (x,y,z) coordinates to the interval [0,1] using the limits supplied or computed from the range of the data. The surface is then viewed by looking at the origin from a direction defined by theta and phi. If theta and phi are both zero the viewing direction is directly down the negative y axis. Changing theta will vary the azimuth and changing phi the colatitude.
图首先转化(X,Y,Z)坐标区间[0,1]使用提供或从范围的数据计算的限制。表面,然后查看在寻找从theta和phi定义一个方向的起源。如果theta和phi均为零观看的方向是直接向下的负y轴。改变theta会有所不同的方位和改变phi的余纬。
There is a hook called "persp" (see setHook) called after the plot is completed, which is used in the testing code to annotate the plot page. The hook function(s) are called with no argument.
有一个钩子被称为"persp"(见setHook)所谓的图完成后,这是在测试代码中使用注释图页。钩子函数(S)被称为不带参数。
Notice that persp interprets the z matrix as a table of f(x[i], y[j]) values, so that the x axis corresponds to row number and the y axis to column number, with column 1 at the bottom, so that with the standard rotation angles, the top left corner of the matrix is displayed at the left hand side, closest to the user.
请注意persp解释zf(x[i], y[j])值作为表的矩阵,使X轴对应行数和Y轴的底部1列,列数,因此,与标准的旋转角度,矩阵的顶部左上角显示在左侧,最靠近用户。
The sizes and fonts of the axis labels and the annotations for ticktype="detailed" are controlled by graphics parameters "cex.lab"/"font.lab" and "cex.axis"/"font.axis" respectively.
尺寸和轴标签的字体和标注为ticktype="detailed"图形参数"cex.lab"/"font.lab"和"cex.axis"/"font.axis"分别控制。
The bounding box is drawn with edges of faces facing away from the viewer (and hence at the back of the box) with solid lines and other edges dashed and on top of the surface. This (and the plotting of the axes) assumes that the axis limits are chosen so that the surface is within the box, and the function will warn if this is not the case.
边界框画实线和虚线的其他边缘和表面上的观众(因此在盒子的背面),面临着来自面的边缘。今(绘制轴)假设轴限的选择,使表面上是内盒,功能会发出警告,如果这种情况并非如此。
值----------Value----------
persp() returns the viewing transformation matrix, say VT, a 4 x 4 matrix suitable for projecting 3D coordinates (x,y,z) into the 2D plane using homogeneous 4D coordinates (x,y,z,t). It can be used to superimpose additional graphical elements on the 3D plot, by lines() or points(), using the function trans3d().
persp()返回查看变换矩阵,说VT,4 x 4适合投影的三维坐标的矩阵(x,y,z)到使用均质4D 2D平面坐标(x,y,z,t)。它可以用来叠加额外的3D绘图上的图形元素,通过lines()或points(),使用功能trans3d()。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
contour and image; trans3d.
contour和image;trans3d。
Rotatable 3D plots can be produced by package rgl: other ways to produce static perspective plots are available in packages lattice and scatterplot3d.
旋转三维图可以由包rgl:包lattice和scatterplot3d其他的方式来产生静电的角度图。
举例----------Examples----------
require(grDevices) # for trans3d[为trans3d]
## More examples in demo(persp) !![更多的例子演示#(persp)!]
## -----------[#-----------]
# (1) The Obligatory Mathematical surface.[(1)强制性的数学表面。]
# Rotated sinc function.[旋转的sinc函数。]
x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
ltheta = 120, shade = 0.75, ticktype = "detailed",
xlab = "X", ylab = "Y", zlab = "Sinc( r )"
) -> res
round(res, 3)
# (2) Add to existing persp plot - using trans3d() :[(2)添加到现有persp图 - 使用trans3d():]
xE <- c(-10,10); xy <- expand.grid(xE, xE)
points(trans3d(xy[,1], xy[,2], 6, pmat = res), col = 2, pch =16)
lines (trans3d(x, y=10, z= 6 + sin(x), pmat = res), col = 3)
phi <- seq(0, 2*pi, len = 201)
r1 <- 7.725 # radius of 2nd maximum[第二个最大的半径]
xr <- r1 * cos(phi)
yr <- r1 * sin(phi)
lines(trans3d(xr,yr, f(xr,yr), res), col = "pink", lwd = 2)
## (no hidden lines)[#(没有隐藏线)]
# (3) Visualizing a simple DEM model[(3)可视化一个简单的DEM模型]
z <- 2 * volcano # Exaggerate the relief[夸大救灾]
x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N)[间距10米(到N)]
y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W)[间距10米(C到W)]
## Don't draw the grid lines : border = NA[#不要绘制网格线:边界=不适用]
par(bg = "slategray")
persp(x, y, z, theta = 135, phi = 30, col = "green3", scale = FALSE,
ltheta = -120, shade = 0.75, border = NA, box = FALSE)
# (4) Surface colours corresponding to z-values[(4)相应的z值的表面颜色]
par(bg = "white")
x <- seq(-1.95, 1.95, length = 30)
y <- seq(-1.95, 1.95, length = 35)
z <- outer(x, y, function(a,b) a*b^2)
nrz <- nrow(z)
ncz <- ncol(z)
# Create a function interpolating colors in the range of specified colors[在指定的颜色的范围内创建一个函数插值颜色]
jet.colors <- colorRampPalette( c("blue", "green") )
# Generate the desired number of colors from this palette[从这个调色板生成所需的颜色数]
nbcol <- 100
color <- jet.colors(nbcol)
# Compute the z-value at the facet centres[z值计算在面中心]
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices[recode的面色指数z值]
facetcol <- cut(zfacet, nbcol)
persp(x, y, z, col=color[facetcol], phi=30, theta=-30)
par(op)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|