gpt4 book ai didi

r - 如何在终端的脚本中显示 r 中的绘图

转载 作者:行者123 更新时间:2023-12-02 14:47:55 24 4
gpt4 key购买 nike

可以从终端运行 r 脚本:

假设我有一个文件“message.r”,其中包含以下内容:

print("hello world")

我可以使用以下命令从终端运行脚本:

$ Rscript message.r
[1] "hello world"

现在假设我有一个脚本,其中包含情节名称 plot.r 的代码,内容如下:

x = c(1,2,3)
y = c(2,3,6)
plot(x,y)

输入命令

Rscript plot.r

什么都没发生

如何从终端显示绘图?

最佳答案

您需要设置设备驱动程序。这会将绘图保存到桌面。

x = c(1,2,3)
y = c(2,3,6)

pdf("~/Desktop/img.pdf")
plot(x,y)
dev.off()

system('open ~/Desktop/img.pdf')

或直接进入终端窗口,

library(txtplot)
x = c(1,2,3)
y = c(2,3,6)

txtplot(x,y)

关于r - 如何在终端的脚本中显示 r 中的绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57791452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com