简体   繁体   English

清除R中的绘图点

[英]Clearing plotted points in R

I am trying to use the animation package to generate an "evolving" plot of points on a map. 我正在尝试使用动画包在地图上生成点的“演化”图。 The map is generated from shapefiles (from the readShapeSpatial/readShapeLines functions). 映射是从shapefile(从readShapeSpatial / readShapeLines函数)生成的。

The problem is when it's plotted in a for loop, the result is additive, whereas the ideal result is to have it evolve. 问题是,将其绘制在for循环中时,结果是可加的,而理想的结果是使其演化。

Are there ways of using par() that I am missing? 有没有办法使用我缺少的par()?

My question is: is there a way to clear just the points ploted from the points function and not clearing the entire figure thus not having to regraph the shapefiles? 我的问题是:有没有办法只清除从点函数绘制的点,而不清除整个图形,从而不必重新绘制shapefile?

in case someone wants to see code: 如果有人想看代码:

# plotting underlying map
newyork <- readShapeSpatial('nycpolygon.shp')
routes <- readShapeLines('nyc.shp')
par(bg="grey25")
plot(newyork, lwd=2, col ="lightgray")
plot(routes,add=TRUE,lwd=0.1,col="lightslategrey")

# plotting points and save to GIF
ani.options(interval=.05)
saveGIF({
  par(bg="grey25")
  # Begin loop
  for (i in 13:44){
    infile <-paste("Week",i,".csv",sep='')
    mydata <-read.csv(file = infile, header = TRUE, sep=",")
    plotvar <- Var$Para
    nclr <- 4
    plotclr <-brewer.pal(nclr,"RdPu")
    class<- classIntervals(plotvar,nclr,style = "pretty")
    colcode <- findColours(class,plotclr)
    points(Var$Lon,Var$Lat,col=colcode)
  }
})

If you can accept a residual shadow or halo of ink, you can over-plot with color ="white" or == to your background choices. 如果您可以接受墨水的残留阴影或光晕,则可以使用背景颜色=“ white”或==来过度绘图。 We cannot access your shape file but you can try it out by adding this line: 我们无法访问您的形状文件,但是您可以通过添加以下行来进行尝试:

points(Var$Lon, Var$Lat, col="grey25")

It may leave gaps in other previously plotted figures or boundaries, because it's definitely not object-oriented. 它可能在其他先前绘制的图形或边界中留下空白,因为它绝对不是面向对象的。 The lattice and ggplot2 graphics models are more object oriented, so if you want to post a reproducible example, that might be an alternate path to "moving" forward. grid和ggplot2图形模型更加面向对象,因此,如果要发布可复制的示例,则可能是“向前”移动的替代路径。 I seem to remember that the rgl package has animation options in its repetoire. 我似乎还记得rgl包的食谱中有动画选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM