2015-08-19 129 views
2

我试图在R中绘制一个条形图,将其保存到PNG文件,然后再绘制一些东西,并再次保存。到目前为止,我的尝试以错误plot.new has not been called yet结束。对应的代码是将绘图保存到图像上,然后在绘图上绘制其他线条并再次保存。

# Draw without lines 
    png(c(name, '.png'), width=480, height=240); 
    stripchart(data, pch=4, method='jitter'); 
    dev.off(); 

    # Draw with with lines 
    png(c(name, '_with_trim_points', '.png'), width=480, height=240); 
    abline(v=points, untf = FALSE, col='red'); 
    abline(v=more__points, untf = FALSE, col='green') 
    dev.off(); 

只需调用stripchart(data, pch=4, method='jitter');第二时间是不是一种选择,因为抖动将是不同的,并用一个不同的散点图中结束。

+0

你能提供一个可重现的例子(包括数据)吗?更易于修改代码。 – Heroka

+0

看看'dev.copy()',最后有一些例子可能有所帮助。 – drmariod

+0

或者 - 随着抖动随机生成 - 设置种子,并在创建新图之前重置它。 – Heroka

回答

1

随着种子和生成的数据

#generate data 
data=data.frame(x=rnorm(40),y=rnorm(40)) 
points=c(-2,0) 
more__points=c(1,2) 



# Draw without lines 
set.seed(123) 
png(paste0(name, '.png'), width=480, height=240); 
stripchart(data, pch=4, method='jitter'); 
dev.off(); 

# Draw with with lines 
set.seed(123) 
png(paste0(name, '_with_trim_points', '.png'), width=480, height=240); 
stripchart(data, pch=4, method='jitter'); 
abline(v=points, untf = FALSE, col='red'); 
abline(v=more__points, untf = FALSE, col='green') 
dev.off(); 

enter image description here enter image description here

0

您可以保存您的图表,并与“saveRDS”,那么你就可以加载它,只要你想继续你的工作保存。