Rscript没有正确绘制matlines

时间:2013-10-14 22:20:19

标签: r bash plot rscript

我正在尝试从 bash 运行 R-script 来绘制 .png-image (R版本3.0.2 on MacOSX10.6.8)。因此我正在使用命令

R CMD BATCH script.R

令人惊讶的是,这会产生一个包含所有内容的.png文件,但这些内容仍然存在。更具体地说,它描绘了一个单一的黑色边线,代表八个定义(彩色)边缘中的第一个。如果我从bash命令行调用 R 并在所有matlines中复制/粘贴R脚本中的代码,则会正确绘制。

R脚本包含以下内容:

#!/usr/bin/env Rscript

temp.table <- read.table("/path/to/firstTable.txt", 
header=TRUE, sep="\t", na.strings="-999.66", dec=".", 
strip.white=TRUE)

colbind <- cbind(temp.table$column1,temp.table$column2,temp.table$column3,temp.table$column4,temp.table$column5,temp.table$column6,temp.table$column7)

colbind.cor <- colbind + 4.7

time <- 1:1020

table.n <- cbind(time,colbind.cor)

colnames(table.n) <- c("time","column1","column2","column3","column4","column5","column6","column7")


para.col <- read.table("/path/to/secondTable.txt", header=TRUE, sep="\t", na.strings="-999.66", dec=",", strip.white=TRUE)

png("/path/to/plot/plot.png", width = 800, height = 400)

plot(table.n, axes=F, xlim=c(0,1020+1), ylim=c(5,40), type='l', ann=F)

par(tcl= -0.2)
axis(2, at=seq(5, 40, by=1), labels=F, lwd=1, lwd.ticks=1)

par(tcl= -0.5)
axis(2, at=seq(5, 1 + 40, by=5), labels=seq(5,40,5), lwd=0, lwd.ticks=2)

par(tcl= -0.2)
axis(1, at=seq(1, 1020, by=10), labels=F, lwd=1, lwd.ticks=1)

par(tcl= -0.5)
axis(1, at=seq(1, 1 + 1020, by=60), labels=seq(0,1020/60,1), lwd=0, lwd.ticks=2)

abline(v=(seq(0,1020,60))+1, col="lightgray", lty="dotted")
abline(h=(seq(5,40,2)), col="lightgray", lty="dotted")

title(sub="title", ylab="Temperature [°C]", xlab="time [min]")

matlines (para.col$column8, type = "l", lty = 1:1, lwd = 1, pch = NULL, col=("#00E1FF"))

matlines (table.n[,c(2,3,4,5,6,7,8)], type = "l", lty = 1:1, lwd = 1, pch = NULL, col=(c("#FF0000","#FF9D00","#A31E00","#362F2A","#B3B3B3","#F5A882","#128794")))

legend("bottomright",legend = c("column1","column2","column3","column4","column5","column6","column7","column8"), lty=c(1,1), lwd=c(2.5,2.5), col=c("#FF0000","#FF9D00","#A31E00","#362F2A","#B3B3B3","#F5A882","#00E1FF","#128794"), text.font=2, cex=0.64) 

dev.off()

rm(list=ls())

我读到了有关可执行性的问题,但是既没有在script.R上使用chmod 755也没有删除第一行(#!/ usr / bin / env Rscript)似乎只是改变了一个黑色的matline。安装是通过here的R-3.0.2.pkg完成的,但使用前一版本时出现了同样的问题。

我真的很感激任何有用的想法!

PS:请注意,此脚本需要来自2个表格的外部输入( firstTable.txt secondTable.txt )。这两个表格均可在filedropper.com/firstandsecondtable下载为 zipped txt-files

0 个答案:

没有答案