R 中的参数、绘图、输出和最佳拟合线

发布于 2024-09-15 11:55:58 字数 508 浏览 5 评论 0原文

我在处理 R 中的一些数据时有几个问题:

  1. 我正在使用以下语句:detailsTable <- read.table(file=commandArgs()[6], header=TRUE, col.names=c(" a", "b", "c", "d", "e")) 似乎该表没有正确加载...但是如果我明确指定要加载的文件的路径,那么一切都会进行出色地。我做错了什么?

  2. 我绘制了上述表格中包含的数据。如何将绘图(例如:plot.savePDF("plot.pdf"))保存到 PDF 文件?

  3. 如何将 cor(detailsTable$a,detailsTable$b) 的输出重定向到文件?以及如何将一个简单的字符串写入文件。例如:“数据的相关性:” + cor(...)

  4. 如何在现有图上绘制最佳拟合线?

所有这些都在 R 中。

非常感谢任何可以提供帮助的人,

ExtremeCoder

I have several questions to do with handling some data in R:

  1. I am using this statement: detailsTable <- read.table(file=commandArgs()[6], header=TRUE, col.names=c("a", "b", "c", "d", "e")) and it seems that the table is not being loaded correctly... but if I specify the path of the file I am loading excplicitly then all goes well. What am I doing wrong?

  2. I plot the data contained in that table mentioned above. How do I save the plot (eg: plot.savePDF("plot.pdf")) to a PDF file?

  3. How could I redirect the output of, for example, cor(detailsTable$a, detailsTable$b) to a file? and how do I write a simple string to a file. eg: "Correlation of the data: " + cor(...)

  4. How do I plot the line of best fit on an existing plot?

All of this is in R.

Many thanks to anyone who can help,

ExtremeCoder

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情定在深秋 2024-09-22 11:55:58

我绘制了上述表格中包含的数据。如何将绘图(例如:plot.savePDF("plot.pdf"))保存到 PDF 文件?

 pdf("filename.pdf")
 plot(...)
 dev.off()

如何将 cor(detailsTable$a,detailsTable$b) 的输出重定向到文件?以及如何将一个简单的字符串写入文件。例如:“数据相关性:” + cor(...)

检查 write.table 手册页 (?write.table)

如何在现有绘图上绘制最佳拟合线?

x <- 1:10
y <- 2 * x + runif(10) 
plot (x, y, pch=20)
fit <- glm(y~x)
coefs <- coef(fit)
abline(coefs, lwd=2, col='red')
# Or also, without finding the coefficients
abline(fit, lwd=2, col='red')

I plot the data contained in that table mentioned above. How do I save the plot (eg: plot.savePDF("plot.pdf")) to a PDF file?

 pdf("filename.pdf")
 plot(...)
 dev.off()

How could I redirect the output of, for example, cor(detailsTable$a, detailsTable$b) to a file? and how do I write a simple string to a file. eg: "Correlation of the data: " + cor(...)

check the write.table manual page (?write.table)

How do I plot the line of best fit on an existing plot?

x <- 1:10
y <- 2 * x + runif(10) 
plot (x, y, pch=20)
fit <- glm(y~x)
coefs <- coef(fit)
abline(coefs, lwd=2, col='red')
# Or also, without finding the coefficients
abline(fit, lwd=2, col='red')
末が日狂欢 2024-09-22 11:55:58

您可以使用sink()重定向输出。

You can redirect output using sink().

手心的温暖 2024-09-22 11:55:58

如何保存您正在生成的绘图取决于您使用的绘图系统。假设它是基本图形,您需要启动 pdf 图形设备,然后绘制到它。

pdf(file = "path/file.pdf", width = 5, height = 5)
...
#plotting commands here
...
dev.off()

How to save the plot you're producing depends on which plotting system you're using. Assuming it's base graphics, you need to start a pdf graphics device, then plot to it.

pdf(file = "path/file.pdf", width = 5, height = 5)
...
#plotting commands here
...
dev.off()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文