plot.zoo(zoo)
plot.zoo()所属R语言包:zoo
Plotting zoo Objects
绘制动物园对象
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Plotting method for objects of class "zoo".
类"zoo"对象的绘制方法。
用法----------Usage----------
## S3 method for class 'zoo'
plot(x, y = NULL, screens, plot.type,
panel = lines, xlab = "Index", ylab = NULL, main = NULL,
xlim = NULL, ylim = NULL, xy.labels = FALSE, xy.lines = NULL,
yax.flip = FALSE, oma = c(6, 0, 5, 0),
mar = c(0, 5.1, 0, if(yax.flip) 5.1 else 2.1),
col = 1, lty = 1, lwd = 1, pch = 1, type = "l", log = "",
nc, widths = 1, heights = 1, ...)
## S3 method for class 'zoo'
lines(x, y = NULL, type = "l", ...)
## S3 method for class 'zoo'
points(x, y = NULL, type = "p", ...)
参数----------Arguments----------
参数:x
an object of class "zoo".
对象类"zoo"。
参数:y
an object of class "zoo". If y is NULL (the default) a time series plot of x is produced, otherwise if both x and y are univariate "zoo" series, a scatter plot of y versus x is produced.
对象类"zoo"。如果y是NULL(默认值)的时间序列图x是,否则,如果两个x和y是单变量"zoo"的系列,y与x产生的散点图。
参数:screens
factor (or coerced to factor) whose levels specify which graph each series is to be plotted in. screens=c(1,2,1) would plot series 1, 2 and 3 in graphs 1, 2 and 1. If not specified then 1 is used if plot.type="single" and seq_len(ncol(x)) otherwise.
因子(或胁迫因子)的水平图要绘制的每个系列都英寸screens=c(1,2,1)将绘制图表1,2和1系列1,2和3。如果没有指定,那么如果plot.type="single"和seq_len(ncol(x))否则。
参数:plot.type
for multivariate zoo objects, "multiple" plots the series on multiple plots and "single" superimposes them on a single plot. Default is "single" if screens has only one level and "multiple" otherwise. If neither screens nor plot.type is specified then "single" is used if there is one series and "mulitple" otherwise. This option is provided for back compatibility. Usually screens is used instead.
多元动物园对象,“多”图多块,“单一”的一系列叠加在同一张图上。默认是“单一”如果screens只有一层"multiple"否则。如果没有screens,也不plot.type指定然后"single"使用,如果有一个系列,"mulitple"否则。提供此选项是为后面的兼容性。通常screens来代替。
参数:panel
a function(x, y, col, lty, ...) which gives the action to be carried out in each panel of the display for plot.type = "multiple".
function(x, y, col, lty, ...)给出了行动,在每块面板的显示进行plot.type = "multiple"。
参数:ylim
if plot.type = "multiple" then it can be a list of y axis limits. If not a list each graph has the same limits. If any list element is not a pair then its range is used instead. If plot.type = "single" then it is as in plot.
如果plot.type = "multiple"然后它可以是一个列表y轴的限制。如果不是一个列表,每个图都有相同的限制。如果任何列表中的元素是不是一对,那么它的使用范围。如果plot.type = "single"然后是作为在plot。
参数:xy.labels
logical, indicating if text labels should be used in the scatter plot, or character, supplying a vector of labels to be used.
逻辑,指示如果text标签应用于在散点图中,或字符,供给要使用的标签的向量。
参数:xy.lines
logical, indicating if lines should be drawn in the scatter plot. Defaults to the value of xy.labels if that is logical, otherwise to FALSE.
逻辑,表示如果lines应在散点图中绘制。默认值xy.labels,如果是逻辑,否则FALSE的价值。
参数:yax.flip
logical, indicating if the y-axis (ticks and numbering) should flip from side 2 (left) to 4 (right) from series to series when type = "multiple".
逻辑,如果y轴(刻度线和编号)应翻转从2侧(左)4(右)系列系列type = "multiple"。
参数:xlab, ylab, main, xlim, oma, mar
graphical arguments, see par.
图形参数,请参阅par。
参数:col, lty, lwd, pch, type
graphical arguments that can be vectors or (named) lists. See the details for more information.
图形参数,可以为向量(命名)的列表。有关详细信息,查看详细资料。
参数:log
specification of log scales as "x", "y" or "xy".
规范的log尺度"x","y"或"xy"。
参数:nc
the number of columns to use when plot.type = "multiple". Defaults to 1 for up to 4 series, otherwise to 2.
数列时使用的plot.type = "multiple"。默认为1到4系列,否则2“。
参数:widths, heights
widths and heights for individual graphs, see layout.
对个别图表的宽度和高度,请参阅layout。
参数:...
additional graphical arguments.
额外的图形参数。
Details
详细信息----------Details----------
The methods for plot and lines are very similar to the corresponding ts methods. However, the handling of several graphical parameters is more flexible for multivariate series. These parameters can be vectors of the same length as the number of series plotted or are recycled if shorter. They can also be (partially) named list, e.g., list(A = c(1,2), c(3,4)) in which c(3, 4) is the default value and c(1, 2) the value only for series A. The screens argument can be specified in a similar way. If plot.type and screens conflict then multiple plots will be assumed. Also see the examples.
plot和lines对应的ts方法是非常类似的方法。然而,几个图形参数的处理更灵活的多元系列。这些参数可以是相同的长度的向量作为绘制的系列数或再循环倘较短。它们也可以是命名列表(部分),例如,list(A = c(1,2), c(3,4))c(3, 4)是默认值和c(1, 2)系列A值。 screens参数可以指定以类似的方式。如果plot.type和screens冲突多条曲线将被假定。还可以看到的例子。
In the case of a custom panel the panel can reference parent.frame$panel.number in order to determine which frame the panel is being called from. See examples.
在自定义面板,面板可以参考的情况下,parent.frame$panel.number,以确定,帧面板被调用。见的例子。
par(mfrow=...) and Axis can be used in conjunction with single panel plots in the same way as with other classic graphics.
par(mfrow=...)和Axis可以使用一并单面板图中的相同的方式与其他经典的图形。
For multi-panel graphics, plot.zoo takes over the layout so par(mfrow=...) cannot be used. Axis can be used within the panels themselves but not outside the panel. See examples.
对于多屏显示图形,plot.zoo需要的布局,所以par(mfrow=...)不能使用。 Axis可以用在面板本身,而是外盘。见的例子。
In addition to classical time series line plots, there is also a simple barplot method for "zoo" series.
除了传统的时间序列线图,也有一个简单的barplot方法"zoo"系列。
参见----------See Also----------
zoo, plot.ts, barplot,
zoo,plot.ts,barplot,
实例----------Examples----------
## example dates[#例如日期]
x.Date <- as.Date(paste(2003, 02, c(1, 3, 7, 9, 14), sep = "-"))
## univariate plotting[#单变量绘制]
x <- zoo(rnorm(5), x.Date)
x2 <- zoo(rnorm(5, sd = 0.2), x.Date)
plot(x)
lines(x2, col = 2)
## multivariate plotting[#多元绘制]
z <- cbind(x, x2, zoo(rnorm(5, sd = 0.5), x.Date))
plot(z, type = "b", pch = 1:3, col = 1:3, ylab = list(expression(mu), "b", "c"))
colnames(z) <- LETTERS[1:3]
plot(z, screens = 1, col = list(B = 2))
plot(z, type = "b", pch = 1:3, col = 1:3)
plot(z, type = "b", pch = list(A = 1:5, B = 3), col = list(C = 4, 2))
plot(z, type = "b", screen = c(1,2,1), col = 1:3)
# right axis is for broken lines[右轴为虚线]
plot(x)
opar <- par(usr = c(par("usr")[1:2], range(x2)))
lines(x2, lty = 2)
# axis(4)[轴(4)]
axis(side = 4)
par(opar)
## Custom x axis labelling using a custom panel.[#自定义X轴标签使用自定义面板。]
# 1. test data[1。测试数据]
z <- zoo(c(21, 34, 33, 41, 39, 38, 37, 28, 33, 40),
as.Date(c("1992-01-10", "1992-01-17", "1992-01-24", "1992-01-31",
"1992-02-07", "1992-02-14", "1992-02-21", "1992-02-28", "1992-03-06",
"1992-03-13")))
zz <- merge(a = z, b = z+10)
# 2. axis tick for every point. Also every 3rd point labelled.[2。每一个点的坐标轴刻度。此外,每隔3点标记。]
my.panel <- function(x, y, ..., pf = parent.frame()) {
fmt <- "%b-%d" # format for axis labels[轴标签的格式]
lines(x, y, ...)
# if bottom panel[如果底部面板]
if (with(pf, length(panel.number) == 0 ||
panel.number %% nr == 0 || panel.number == nser)) {
# create ticks at x values and then label every third tick[将刻度线创建x值,然后每三剔标记]
axis(side = 1, at = x, labels = FALSE)
ix <- seq(1, length(x), 3)
labs <- format(x, fmt)
axis(side = 1, at = x[ix], labels = labs[ix], tcl = -0.7, cex.axis = 0.7)
}
}
# 3. plot[3。图]
plot(zz, panel = my.panel, xaxt = "n")
# with a single panel plot a fancy x-axis is just the same[一个单一的面板图一个奇特的x轴是一样的]
# procedure as for the ordinary plot command[程序的普通绘图命令]
plot(zz, screen = 1, col = 1:2, xaxt = "n")
# axis(1, at = time(zz), labels = FALSE)[轴(1 =时间(ZZ),标签= FALSE)]
tt <- time(zz)
axis(side = 1, at = tt, labels = FALSE)
ix <- seq(1, length(tt), 3)
fmt <- "%b-%d" # format for axis labels[轴标签的格式]
labs <- format(tt, fmt)
# axis(1, at = time(zz)[ix], labels = labs[ix], tcl = -0.7, cex.axis = 0.7)[轴线(1 =时间(zz)的[㈨],标签=实验室[㈨],的tcl = -0.7,cex.axis = 0.7)]
axis(side = 1, at = tt[ix], labels = labs[ix], tcl = -0.7, cex.axis = 0.7)
legend("bottomright", colnames(zz), lty = 1, col = 1:2)
## plot a mulitple ts series with nice x-axis using panel function[#绘制多张TS系列不错的x轴面板功能]
tab <- ts(cbind(A = 1:24, B = 24:1), start = c(2006, 1), freq = 12)
pnl.xaxis <- function(...) {
lines(...)
panel.number <- parent.frame()$panel.number
nser <- parent.frame()$nser
# if bottom panel[如果底部面板]
if (!length(panel.number) || panel.number == nser) {
tt <- list(...)[[1]]
ym <- as.yearmon(tt)
mon <- as.numeric(format(ym, "%m"))
yy <- format(ym, "%y")
mm <- substring(month.abb[mon], 1, 1)
if (any(mon == 1))
# axis(1, tt[mon == 1], yy[mon == 1], cex.axis = 0.7)[轴(1,TT [周一== 1],YY [MON == 1],cex.axis = 0.7)]
axis(side = 1, at = tt[mon == 1], labels = yy[mon == 1], cex.axis = 0.7)
# axis(1, tt[mon > 1], mm[mon > 1], cex.axis = 0.5, tcl = -0.3)[轴(1,TT [周一]毫米[周一1],cex.axis = 0.5,TCL = -0.3)]
axis(side = 1, at = tt[mon > 1], labels = mm[mon > 1], cex.axis = 0.5, tcl = -0.3)
}
}
plot(as.zoo(tab), panel = pnl.xaxis, xaxt = "n", main = "Fancy X Axis")
## Another example with a custom axis[一个自定义轴的另一个例子#]
# test data[测试数据]
z <- zoo(matrix(1:25, 5), c(10,11,20,21))
colnames(z) <- letters[1:5]
plot(zoo(coredata(z)), xaxt = "n", panel = function(x, y, ..., Time = time(z)) {
lines(x, y, ...)
# if bottom panel[如果底部面板]
pf <- parent.frame()
if (with(pf, panel.number %% nr == 0 || panel.number == nser)) {
axis(side = 1, at = x, labels = Time)
}
})
## plot with left and right axes[#图有左,右轴]
## modified from http://www.mayin.org/ajayshah/KB/R/html/g6.html[#从http://www.mayin.org/ajayshah/KB/R/html/g6.html修改]
set.seed(1)
z <- zoo(cbind(A = cumsum(rnorm(100)), B = cumsum(rnorm(100, mean = 0.2))))
opar <- par(mai = c(.8, .8, .2, .8))
plot(z[,1], type = "l",
xlab = "x-axis label", ylab = colnames(z)[1])
par(new = TRUE)
plot(z[,2], type = "l", ann = FALSE, yaxt = "n", col = "blue")
# axis(4)[轴(4)]
axis(side = 4)
legend(x = "topleft", bty = "n", lty = c(1,1), col = c("black", "blue"),
legend = paste(colnames(z), c("(left scale)", "(right scale)")))
usr <- par("usr")
# if you don't care about srt= in text then mtext is shorter:[如果你不关心SRT =文本,多行文字变短:]
# mtext(colnames(z)[2], 4, 2, col = "blue")[多行文字(colnames(Z)[2],4个,2个,列=“蓝”)]
text(usr[2] + .1 * diff(usr[1:2]), mean(usr[3:4]), colnames(z)[2],
srt = -90, xpd = TRUE, col = "blue")
par(opar)
# automatically placed point labels[自动放置点标签]
## Not run: [#不运行:]
library("maptools")
pointLabel(time(z), coredata(z[,2]), labels = format(time(z)), cex = 0.5)
## End(Not run)[#(不执行)]
## plot one zoo series against the other.[#对其他绘制一个动物园系列。]
plot(x, x2)
plot(x, x2, xy.labels = TRUE)
plot(x, x2, xy.labels = 1:5, xy.lines = FALSE)
## shade a portion of a plot and make axis fancier[底纹部分的图,使轴爱好者]
v <- zooreg(rnorm(50), start = as.yearmon(2004), freq = 12)
plot(v, type = "n")
u <- par("usr")
rect(as.yearmon("2007-8"), u[3], as.yearmon("2009-11"), u[4],
border = 0, col = "grey")
lines(v)
axis(1, floor(time(v)), labels = FALSE, tcl = -1)
## shade certain times to show recessions, etc.[#遮阳特定的时间显示经济衰退等。]
v <- zooreg(rnorm(50), start = as.yearmon(2004), freq = 12)
plot(v, type = "n")
u <- par("usr")
rect(as.yearmon("2007-8"), u[3], as.yearmon("2009-11"), u[4],
border = 0, col = "grey")
lines(v)
axis(1, floor(time(v)), labels = FALSE, tcl = -1)
## fill area under plot[根据图填充区域]
pnl.xyarea <- function(x, y, fill.base = 0, col = 1, ...) {
lines(x, y, ...)
panel.number <- parent.frame()$panel.number
col <- rep(col, length = panel.number)[panel.number]
polygon(c(x[1], x, tail(x, 1), x[1]),
c(fill.base, as.numeric(y), fill.base, fill.base), col = col)
}
plot(zoo(EuStockMarkets), col = rainbow(4), panel = pnl.xyarea)
## barplot[#barplot]
x <- zoo(cbind(rpois(5, 2), rpois(5, 3)), x.Date)
barplot(x, beside = TRUE)
## 3d plot[#3D绘图]
## The persp function in R (not part of zoo) works with zoo objects.[#persp R(动物园)中的功能与动物园对象。]
## The following example is by Enrico Schumann.[#下面的例子是由恩里科·舒曼。]
## https://stat.ethz.ch/pipermail/r-sig-finance/2009q1/003710.html[#https://stat.ethz.ch/pipermail/r-sig-finance/2009q1/003710.html]
nC <- 10 # columns[列]
nO <- 100 # observations[观察]
dataM <- array(runif(nC * nO), dim=c(nO, nC))
zz <- zoo(dataM, 1:nO)
persp(1:nO, 1:nC, zz)
# interactive plotting[交互式绘图]
## Not run: [#不运行:]
library("TeachingDemos")
tke.test1 <- list(Parameters = list(
lwd = list("spinbox", init = 1, from = 0, to = 5, increment = 1, width = 5),
lty = list("spinbox", init = 1, from = 0, to = 6, increment = 1, width = 5)
))
z <- zoo(rnorm(25))
tkexamp(plot(z), tke.test1, plotloc = "top")
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|