我正在尝试从 R 中的 z 分数矩阵绘制图表,我想构建一个函数来使用列标题作为标题的一部分遍历每一列并将每个图表保存为 png。我想我知道如何进行迭代并将图形保存为 png,但我一直坚持使用向量作为字符串。我尝试上传没有列标题的矩阵,然后将 matrix[1,] 存储为要使用的变量“标题”。然后我尝试绘制:
plot(1:30, rnorm(30), ylim=c(-10,10), yaxs="i", xlab = "Region", ylab = "Z-Score",main = "CNV plot of " + headers[i], type = "n")
我得到:
Warning message:
In Ops.factor(left, right) : + not meaningful for factors
我尝试不使用“+”,它说:
Error: unexpected symbol in ...
所以然后我环顾四周,找到了 'paste(headers[i],collapse="") ,虽然我可以替换它,但它只是将数字 '28' 作为标题。
我已经尝试了我认为是另一个潜在的解决方案:
plot(1:30, rnorm(30), ylim=c(-10,10), yaxs="i", xlab = "Region", ylab = "Z-Score",main = "Z-scores of " $headers[i], type = "n")
我得到:
Error in "Z-scores of "$headers :
$ operator is invalid for atomic vectors
我是 R 新手,如果我在谷歌搜索数小时后碰巧偶然发现了正确的指南/教程,这似乎会变得如此简单,但我真的没有那种时间在我手上。任何建议,指针或解决方案都会很棒?