0
我是R的新手,从这个简单的问题出发。我想绘制包含时间值的输入文件的值。输出图像应该包含蓝线(对于Dist为09.0的行)和红线(对于Dist为04.0的行)。从R中的文件绘制时间值的最简单方法是什么?
我设法生成输入整数值直接进入graph.r
的图形,但现在我想graph.r
从input.txt
获取这些值来代替,并让他们格式化为时间(h:mm:ss的)。这是可能的,还是我必须解析input.txt
之前喂它到R?
input.txt中
Date(x) Dist Time(y)
120926 09.0 1:54:42
121001 04.0 0:19:00
121202 04.0 0:18:53
121206 09.0 1:13:19
graph.r
#!/usr/bin/env Rscript
# Define the cars vector with 5 values
input <- 'path/to/input.txt'
nine <- file(input) #how to parse it?
four <- c(3600, 12:00, 16, 4, 9) #this fails because of "12:00"
# Set output file type to png
png("output.png", width=320, height=240)
# Graph using blue points for Dist 9, and red for Dist 4.
plot(nine, type="o", col="blue")
plot(four, type="o", col="red")
# Output to file
dev.off()
我不知道我很理解你的第二句话。为什么点击?是否不可能以非交互方式执行此操作? – octosquidopus
是的,你不需要使用locator()函数为你的图例选择点,但是你需要手动提供x和y值。 –
如果这对你有用,你能接受答案吗? –