Plotting incrementally in R and not resetting

送分小仙女□ 提交于 2019-12-05 19:28:58

Here's a simple example of how to do this by setting the points which should be plotted and only adding points when this criteria is met:

# set the frequency with which to plot points
plotfreq <- 10

# set the x and y limits of the graph
x.limits <- c(1,100)
y.limits <- c(0,100)

# initialise a vector and open a plot
result <- vector(mode="numeric",length=100)
plot(result,ylim=y.limits,xlim=x.limits,type="n")

# do the plotting
plot.iterations <- seq(plotfreq,length(result),by=plotfreq)
for (i in seq_along(result)) {
  result[i] <- result[i] + i

  # only plot if the data is at the specified interval
  if (i %in% plot.iterations) {
    points(i,result[i])
  }

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!