我正在使用R进行一些非常简单的数据可视化(*注:我正在R Studio中工作)。我正在加载一个包含两个每日价格序列的csv文件,列标题为“ price1”和“ price2”。我在这里寻找的只是创建每个时间序列的线图,但是每次都返回一个箱形图。例如,尝试绘制时间序列“ price1”在我的代码中如下所示:
#Load csv into dataframe
data <- read.csv("pathtofile.csv")
#Plot time series 'price1'
plot(data["price1"])
这个问题似乎非常直接,但是我对于使用R还是比较陌生,所以我不确定这里是否有一个简单的语法错误让我无法理解。
修改
str(数据)的输出:
'data.frame': 1382 obs. of 6 variables:
$ time : Factor w/ 1382 levels "00:00:00","00:01:00",..: 1022 1023 1024
1025 1026 1027 1028 1029 1030 1031 ...
$ feb : num 57 57 57 57 57 ...
$ jun : num 57.7 57.7 57.7 57.7 57.7 ...
$ X : logi NA NA NA NA NA NA ...
$ ret_f: num 0.035 0 -0.015 0.03 0 -0.02 0.02 -0.025 0.01 0 ...
$ ret_j: num 0.01 0 0.005 0 -0.005 0 0.005 0 0 -0.015 ...
dput(数据[1:10,])的输出:
structure(list(time = structure(1022:1031, .Label = c("00:00:00",
"00:01:00", "00:02:00", "00:03:00", "00:04:00", "00:05:00", "00:06:00",
"00:07:00", "00:08:00", "00:09:00", "00:10:00", "00:11:00", "00:12:00",
"00:13:00", "00:14:00", "00:15:00", "00:16:00", "00:17:00", "00:18:00",
"00:19:00", "00:20:00", "00:21:00", "00:22:00", "00:23:00", "00:24:00",
"00:25:00", "00:26:00", "00:27:00", "00:28:00", "00:29:00", "00:30:00",
"00:31:00", "00:32:00", "00:33:00", "00:34:00", "00:35:00", "00:36:00",
"00:37:00", "00:38:00", "00:39:00", "00:40:00", "00:41:00", "00:42:00",
"00:43:00", "00:44:00", "00:45:00", "00:46:00", "00:47:00", "00:48:00",
"00:49:00", "00:50:00", "00:51:00", "00:52:00", "00:53:00", "00:54:00",
"00:55:00", "00:56:00", "00:57:00", "00:58:00", "00:59:00", "01:00:00",
"01:01:00", "01:02:00", "01:03:00", "01:04:00", "01:05:00", "01:06:00",
"01:07:00", "01:08:00", "01:09:00", "01:10:00", "01:11:00", "01:12:00",
"01:13:00", "01:14:00", "01:15:00", "01:16:00", "01:17:00", "01:18:00",
"01:19:00", "01:20:00", "01:21:00", "01:22:00", "01:23:00", "01:24:00",
"01:25:00", "01:26:00", "01:27:00", "01:28:00", "01:29:00", "01:30:00",
....
"57.23"), class = "factor"), feb = c(56.95, 56.985, 56.985, 56.97,
57, 57, 56.98, 57, 56.975, 56.985), jun = c(57.69, 57.7, 57.7,
57.705, 57.705, 57.7, 57.7, 57.705, 57.705, 57.705), X = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA), ret_f = c(0.035, 0, -0.015,
0.03, 0, -0.02, 0.02, -0.025, 0.01, 0), ret_j = c(0.01, 0, 0.005,
0, -0.005, 0, 0.005, 0, 0, -0.015)), row.names = c("18:00:00",
"18:01:00", "18:02:00", "18:03:00", "18:04:00", "18:05:00", "18:06:00",
"18:07:00", "18:08:00", "18:09:00"), class = "data.frame")
答案 0 :(得分:0)
我认为您需要指定“虚拟” x值或指定绘图类型。
尝试:
plot(data["price1"], type='l')
或
plot(seq_along(data["price1"]), data["price1"], type='l')