Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R的格式化输出_R_Plot_Gnu_Output - Fatal编程技术网

R的格式化输出

R的格式化输出,r,plot,gnu,output,R,Plot,Gnu,Output,我想在GNU绘图上绘制R的输出。例如,我有一个存储整数的矩阵x,我把矩阵y设为y,我不完全清楚你是想把两个向量相对地画出来,还是想用矩阵做些什么。我想是第一个。让我们创建一些示例数据: x = 1:10 y = x^2 z = cbind(x, y) 接下来,我们将其放入一个文件中: write.table(z, file = "/tmp/spam", row.names = FALSE, col.names = FALSE) 如果我们检查输出: $ cat /tmp/spam 1

我想在GNU绘图上绘制R的输出。例如,我有一个存储整数的矩阵
x
,我把矩阵
y
设为
y,我不完全清楚你是想把两个向量相对地画出来,还是想用矩阵做些什么。我想是第一个。让我们创建一些示例数据:

x = 1:10
y = x^2    
z = cbind(x, y)
接下来,我们将其放入一个文件中:

write.table(z, file = "/tmp/spam", row.names = FALSE, col.names = FALSE)
如果我们检查输出:

$ cat /tmp/spam
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
我想这就是你需要的。或者,只需执行以下操作:

plot(y~x, z, type = "l")

完全避免GNUplot。或者更好地使用
ggplot2

require(ggplot2); theme_set(theme_bw())
qplot(x, y, data = data.frame(z), geom = "line")

在TeachingDemos软件包中,R和gnuplot之间有一组基本的接口函数,请参见
?gp.open
。它们可以做您想做的事情,或者您可以查看代码,以获取以gnuplot所需格式创建数据文件的示例。

尝试t(x)或t(矩阵)垂直排列它们阅读
?write.table
。查看选项
col.names
row.names
sep
quote
。另外,如果您使用的是R,为什么要使用GNU plot?…或使用R进行绘图。我喜欢只使用一种工具。特别是使用
ggplot2
时,R中有一个非常强大的绘图环境。我添加了一些R生成的示例绘图。
require(ggplot2); theme_set(theme_bw())
qplot(x, y, data = data.frame(z), geom = "line")