[英]image.plot does not create new image
这是生成图像图的代码示例。 但是由于某种原因,当我重新运行它时,不会创建新图像,但是会覆盖现有图。 但是我希望它可以创建一个新图像,因为它有一个特定的参数“ add”来指定必须将其添加到现有绘图中(但默认值为FALSE)。
有人知道这是怎么回事吗?
require(fields)
mat <- matrix(runif(5*5), ncol=5)
mat[1,3] <- NA
image.plot(seq(1,5,1),seq(1,5,1), mat, col = tim.colors(64), legend.only=TRUE)
par(oma=c(0,0,0,6))
par(new = TRUE)
image(seq(1,5,1),seq(1,5,1),matrix(1,5,5), col = gray(0.8), xlab = "", ylab = "", axes = F)
par(new = TRUE)
image(seq(1,5,1),seq(1,5,1),mat, xlab="Hour of the Day", ylab = "Day of the Week", col = tim.colors(64), axes = F)
par(oma=c(0,0,0,0))
编辑我对设备等了解不多。但是当我执行例如plot(1:10)
然后plot(10:1)
,我确实知道(并且我正在RStudio中工作)清除图形窗口并显示的第二个绘图没有添加到第一个绘图中(在RStudio中,您当然可以使用附加功能,也可以浏览以前的图形,但是如果我在纯R控制台中执行相同的操作,则当第二个图称为)。 这就是我想要的,我只是希望第二次调用image.plot时会清除图形窗口,而不是覆盖上一次调用image.plot时的图像。
您注意到par
的“ new”参数的含义出现了奇数反转。 这是帮助页面说明:
new
logical, defaulting to FALSE. If set to TRUE, the next high-level plotting command
(actually plot.new) should not clean the frame before drawing as if it were on a new
device. It is an error (ignored with a warning) to try to use new = TRUE on a device
that does not currently contain a high-level plot.
我认为,如果在image.plot
命令中设置legend.only=T
,它将自动设置par(new=TRUE)
。 如果先绘制图像,然后再添加图例,则可以使用图例。 在这里,您必须放弃一个par(new=TRUE)
:
require(fields)
mat <- matrix(runif(5*5), ncol=5)
mat[1,3] <- NA
par(oma=c(0,0,0,6))
#par(new = TRUE)
image(seq(1,5,1),seq(1,5,1),matrix(1,5,5), col = gray(0.8), xlab = "", ylab = "", axes = F)
par(new = TRUE)
image(seq(1,5,1),seq(1,5,1),mat, xlab="Hour of the Day", ylab = "Day of the Week", col = tim.colors(64), axes = F)
par(oma=c(0,0,0,0))
image.plot(seq(1,5,1),seq(1,5,1), mat, col = tim.colors(64), legend.only=TRUE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.