找回密码
 注册
查看: 1679|回复: 0

R语言 SVGAnnotation包 animate()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-22 21:05:56 | 显示全部楼层 |阅读模式
animate(SVGAnnotation)
animate()所属R语言包:SVGAnnotation

                                        A simple-minded illustration of  animating a scatter plot
                                         一个头脑简单的插图,动画散点图

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This function provides an illustration of animating a scatter plot in a simple-minded manner. The idea is that we take an existing  scatter plot of variables X and Y  illustrating observations at a particular time period. Then, we move the points in that scatter plot to their locations  at the next time period and then again for the next time period. When we start a new time period, the points change color.
此功能提供了一个头脑简单的方式散点图动画插图。我们的想法是,我们必须采取现有散点图变量X和Y,说明在一个特定的一段时间的观察。然后,我们在该散点图移动点的位置,在未来一段时间,然后再次在未来的一段时间。当我们开始新的一段时间内,点改变颜色。

If you use plotting characters in the original plot that have multiple segments or paths, you will need to call groupByPch in order to move these segments into  their own groups. This results in the correct number of SVG elements corresponding to the observations and then the animation will work fine.
如果您使用绘图原作剧情中的人物有多个分部或路径,你将需要调用groupByPch,以推动这些细分市场,为自己的团体。这个结果,然后在相应的意见和SVG元素的正确动画,做工精细。


用法----------Usage----------


animate(file, data,
        which = if(ncol(data) > 2)
                  data[,3]
                else
                  stop("you must specify which to identify the time steps"),
        xlim = NA, ylim = NA,
        interval = 2,
        begin = interval,
        dur = "10s",
        colors = character(),   
        radii = list(),
        digits = 4,
        doc = xmlPlot(file),
        plotRegion = getPlotRegionNodes(doc)[[1]],
        points = getPlotPoints(plotRegion),
        dropFirst = TRUE,
        labels = character(),
        hook = NULL, ..., .args,
        addTypes = TRUE)



参数----------Arguments----------

参数:file
the SVG file containing the original scatter plot
SVG文件包含原始的散点图


参数:data
the data to be plotted. This is a data frame or matrix containing the X and Y values for all time periods of interest.
要绘制的数据。这是一个数据框或矩阵X和Y值包含所有感兴趣的时段。


参数:which
a vector that identifies the "time" variable. This is used to group the observations so we move all the points within a given group at the same time. This is likely to be a factor such as day of week, or month, or year
矢量标识“时间”变量。这是用来组织的意见,所以我们将在同一时间内都指向一个给定的组。这是可能的因素,如星期或一个月,或一年


参数:xlim
the range in data coordinates for the horizontal axis. This should  be the same as  used for the original scatter plot. It is vitally important that these values (and the corresponding ylim) values give the actual range of the X range of the entire data region  not just the xlim used in creating the initial plot. In general, we want the value of par("usr") for the particular plotting region. Since svgPlot inserts this into the SVG document, we are better off using the default value.  
在数据的范围,坐标横轴。这应该是为原来的散点图使用的相同。这是非常重要的,这些值(和相应的ylim)值给整个数据区域不只是用于创建初始的图xlim X系列的实际范围。在一般情况下,我们希望par("usr")特别策划区域的价值。 svgPlot这将SVG文档中插入以来,我们最好使用默认值。


参数:ylim
the range in data coordinates for the vertical axis.
在数据的范围为纵轴的坐标。


参数:begin
the number of seconds before the animation starts. The original plot will be displayed (without motion) for this period
动画开始之前的秒数。此期间,原来的图将显示(不运动)


参数:interval
the number of seconds each step of the animation lasts.  One can either specify this or the total duration of the entire animation, but not both.
持续的秒数的动画的每一步。可以指定或整个动画的总工期,但不能同时。


参数:colors
a  vector of colors to use for the points in each time period. This should be the same length as the unique values in which.
在每个时间段的分颜色的向量使用。这应该是相同的长度在which独特的价值观。


参数:dur
how long the animation should last.  This time is divided evenly between the different time periods. This defaults to seconds.  Instead of giving this total amount of time, one can use interval to specify the amount of time for each step of the animation.  
动画要持续多久。这一次是不同时期之间平均分配。默认为秒。这段时间的总金额,而不是给人们可以使用interval指定的时间,每一步动画。


参数:digits
the number of digits to write for transformed (x, y) pairs written to the SVG file.
位数写的转化(X,Y)对写入SVG文件。


参数:doc
the XMLInternalDocument created by parsing the contents of file. This can be passed directly if the SVG plot has already been parsed. This allows one to read the document and process it before adding the animation.
XMLInternalDocument创建,解析file的内容。这可以直接通过SVG的图已经被解析。这允许一个读取文件,并添加动画之前处理它。


参数:points
the list of SVG nodes representing the points in the original scatter plot.
SVG的节点代表在原来的散点图点名单。


参数:plotRegion
the SVG node/element (<g>) corresponding to the plotting region in which the animation is occurring.  
SVG节点/元素(<g>)相应的图发生在哪个区域的动画。


参数:dropFirst
either a logical value or a value of the level in thewhich vector. This is allows the caller to have the function drop the observations in data that have already been plotted. These correspond to the first time point. We animate the rest of the points and this saves the caller having to perform the subset. This is especially useful as this allows the function to compute the xlim and ylim values on the entire data set and then drop the points that have already been plotted.
一个逻辑值或值的which向量水平。这是允许呼叫者data已经绘制功能下降的意见。这些对应于第一时间点。我们其余的点的动画,这样可以节省执行的子集的来电。这是特别有用的,因为这可以让函数来计算xlim和ylim整个数据集上的值,然后删除已绘制的点。


参数:labels
a character vector whose values will be displayed sequentially at the start of each step of the animation in the middle of the plot in light gray color.
一个字符向量,其值将显示顺序开始在浅灰色的图中每个动画一步。


参数:radii
a list or a character vector naming a column in data. This is a list of values with one element for each observation in the original plot. Each such element is a numeric vector with as many elements as there are stages in the animation, excluding the first. These values are used to multiply the radius of the observation's circle on the display at the corresponding stage of the animation. Note that they scale the original radius; they do not cumulate.  
一个列表或一个字符向量,一列命名data。这是一个元素的值列表中的每个观察原始的剧情。每个这样的元素,是一个有许多元素在动画阶段的数字向量,不包括第一。这些值是用来观察的圆的半径乘以在相应阶段的动画显示。需要注意的是,他们扩展原有的半径;他们不累积。


参数:hook
a callback function that can be specified by the caller which will be invoked for each observation and for each step in the animation as we are creating the animation in R. (It is not called during the viewing of the animation, just in the preparation!) This can be used to adjust or add to the animation, e.g. put in trail lines, update text, synchronize with another plot. The function is called with the SVG element representing the observation/point on the plot, a list giving the details about the animation (the id, when the step begins, its duration, the index of the observation and the step in the animation) and any additional arguments passed via ... or .args.  
将每个观察和动画中的每一步,我们正在创建R中的动画(它不只是在观看动画的准备,称为调用的来电者,可以通过指定一个回调函数! )这可以用来调整或添加到动画,例如:把行步道,更新文本,同步与另一个图。与SVG元素的图,提供有关动画(ID,当始于足下,其持续时间,观察指数和动画中的一步列表)的细节上观察/点和函数被调用任何额外的参数传递通过...或.args。


参数:...
additional arguments that are passed to the calls to hook
额外的参数传递给调用hook


参数:.args
additional arguments that are passed to the calls to hook but which are specified as a list to avoid conflicts with names in this function.
额外的参数传递给调用hook但指定为在此功能的名称列表,以避免冲突。


参数:addTypes
a logical value which if TRUE causes the function to add a type attribute to the new circle SVG elements it creates that identifies each of them as a 'plot-point'.
一个逻辑值,如果TRUE导致的功能type属性添加到新的圆圈SVG元素,它创建,每个标识为“积点”。


值----------Value----------

A list with two elements.
有两个元素的列表。


参数:circles
a list of the newly created or updated nodes corresponding to the observations in the plot.
一个新创建或更新的节点相应的意见,在小区的名单。


参数:details
a list with information about the animation such as the starting points of the different stages/steps, their duration, their names, the interval (as a number) and the starting offset. The first three elements are character vectors; the last two are numbers.
与信息有关的不同阶段/步骤的出发点,其持续时间,他们的名字,间隔(数字)和起始偏移量,如动画列表。前三个元素是特征向量;最后两个数字。


作者(S)----------Author(s)----------


Duncan Temple Lang



参考文献----------References----------



参见----------See Also----------

svgPlot svg groupByPch
svgPlotsvggroupByPch


举例----------Examples----------



#[]
# 4 points[4分]
#  1 going along a 45 degree line[1要沿着45度线]
#  one going [1准备]
#[]
#[]

p1 = matrix(c( 2, 2, 2,
               3, 3, 3,
               4, 4, 4,
               5, 5, 5,
               6, 6, 6), 5, , byrow = TRUE)

p2 = matrix(c( 12, 2, 1,
               10, 3, 1.2,
                8, 4, 1.4,
                6, 5, 1.5,
                4, 6, 3), 5, , byrow = TRUE)


p3 = cbind(seq(4, 12, length = 5),
           rep(6, 5),
           c(1.5, 3, 5, 3, 1.5))

D = data.frame(rbind(p1, p2, p3))

names(D) = c("x", "y", "radius")
D$time = rep(1:5, 3)
D$id = rep(1:3, each = 5)
D = D[order(D$time),]


if(FALSE) {
plot(0, xlim = range(D$x), ylim = range(D$y))
by(D, D$id, function(x){
             col = c("red", "green", "blue")[x[,"id"]]
             points(x[,1], x[,2], col = col)
             text(x[,1] + .1, x[,2] + .1, 1:nrow(x), col = col)            
             lines(x[,1:2], col = col[1])
           })
}

#########################################[########################################]

library(SVGAnnotation)

   # We specify the xlim and ylim to ensure the other[我们指定的xlim和ylim,以确保其他]
   # points in time will[时间点]
pp = svgPlot({plot(y ~ x, subset(D, time == 1),
                   pch = 21,
                   col = c("red", "green", "blue"),
                   bg = c("red", "green", "blue"),
                   xlim = range(D$x), ylim = range(D$y)
                  )
                    # Add horizontal and vertical lines at suitable positions.[添加水平线和垂直线,在合适的岗位。]
               abline (h = c(2, 4, 6), col = "lightgray", lty = 3)
               abline (v = c(2, 7, 12), col = "lightgray", lty = 2)              
              })

animate(pp, D, "time", dropFirst = TRUE,
         labels = seq(2005, length = 5),
           begin = 1, radii = "radius")

saveXML(pp, "gm1.svg")



###############[##############]
# This illustrates how we use groupByPch() when we use plotting[这说明我们如何使用时,我们使用绘图groupByPch()]
# symbols that correspond to multiple SVG elements.[对应多个SVG元素的符号。]

pch = c(7, 8, 10)
pp = svgPlot({plot(y ~ x, subset(D, time == 1), pch = pch,
                   col = c("red", "green", "blue"),
                   bg = c("red", "green", "blue"),
                   xlim = range(D$x), ylim = range(D$y))
               with(D[D$time == 1,], points(x, y, col = c("red", "green", "blue")))
               with(D[D$time != 1,], points(x, y, col = 'lightgray'))              
               abline (h = c(2, 4, 6), col = "lightgray", lty = 3)
               abline (v = c(2, 7, 12), col = "lightgray", lty = 2)              
              })

rr = getPlotRegionNodes(pp)[[1]]
groupByPch(xmlChildren(rr), pch)

animate(pp, D, "time", dropFirst = TRUE, labels = seq(2005, length = 5),
          points = xmlChildren(rr))

saveXML(pp, "gm4.svg")


#######################[######################]

## Not run: [#无法运行:]
load(url("http://www.omegahat.org/SVGAnnotation/tests/myTraffic.rda"))
svg("occ.xml")
plot(Flow1 ~ Occ1, traffic[1:288,],
      xlim = range(traffic$Occ1),
      ylim = range(traffic$Flow1),
      main = "Flow versus Occupancy")
abline(v = .2, col = "red")
dev.off()

     # Now we can animate[现在,我们可以动画]
z = animate("occ.xml", traffic[-(1:288), c("Occ1", "Flow1")],
             weekdays(traffic$time[-(1:288)]),
             xlim = range(traffic$Occ1), ylim = range(traffic$Flow1),
             dur = "10s")

## End(Not run)[#结束(不运行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-22 15:44 , Processed in 0.029751 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表