我正在努力让下面的代码工作,我的大脑是非常累.感谢对解决问题的所有建议.我试图打印所有图像的开始和结束日期使用ggplot.然而,得到一个又一个错误.代码测试如下:
library(ggplot2)
set.seed(123)
from_dates_1 <- as.POSIXct(c("2021-06-19 10:04:00", "2021-06-20 00:58:00", "2021-06-23 18:26:00", "2021-07-07 18:15:00", "2021-07-11 12:42:00", "2021-07-31 23:26:00", "2021-08-07 22:00:00", "2021-08-11 14:36:00", "2021-08-13 16:08:00", "2021-08-17 00:24:00", "2021-08-26 04:28:00", "2021-09-04 09:56:00", "2021-09-05 18:50:00", "2021-09-08 18:50:00", "2021-09-13 16:28:00", "2021-09-17 02:10:00", "2021-09-19 18:50:00", "2021-09-22 18:36:00", "2021-09-27 12:10:00", "2022-05-15 22:44:00", "2022-05-17 18:56:00", "2022-05-17 20:58:00", "2022-05-18 22:00:00", "2022-05-22 08:02:00", "2022-05-23 23:14:00", "2022-05-24 11:58:00", "2022-05-24 13:02:00", "2022-05-24 14:44:00", "2022-05-25 12:48:00", "2022-05-26 15:08:00", "2022-05-26 16:22:00", "2022-05-26 21:28:00", "2022-05-29 19:46:00", "2022-05-30 01:24:00", "2022-05-31 12:26:00", "2022-06-09 22:58:00", "2022-06-10 16:48:00", "2022-06-11 15:12:00", "2022-06-11 16:12:00", "2022-06-16 13:44:00", "2022-06-17 01:52:00", "2022-06-20 02:58:00", "2022-06-21 03:20:00", "2022-06-24 00:08:00", "2022-06-24 19:12:00", "2022-06-26 13:34:00", "2022-06-26 16:45:00", "2022-06-27 00:34:00", "2022-06-28 02:28:00", "2022-06-28 22:00:00", "2022-06-30 05:02:00", "2022-07-01 15:48:00", "2022-07-06 00:20:00", "2022-07-13 15:52:00", "2022-07-14 14:32:00", "2022-07-15 01:58:00", "2022-07-17 01:42:00", "2022-07-23 14:08:00", "2022-07-23 17:26:00", "2022-07-23 22:15:00", "2022-07-24 17:14:00", "2022-07-25 00:28:00", "2022-07-25 10:08:00", "2022-07-25 12:20:00", "2022-07-29 23:44:00", "2022-07-31 05:58:00", "2022-08-01 00:10:00", "2022-08-01 18:36:00", "2022-08-03 10:58:00", "2022-08-03 21:06:00", "2022-08-04 05:26:00", "2022-08-14 17:22:00", "2022-08-19 17:12:00", "2022-08-22 12:38:00", "2022-08-26 13:58:00", "2022-08-28 23:15:00", "2022-09-03 10:56:00", "2022-09-03 22:26:00", "2022-09-04 21:06:00", "2022-09-05 20:22:00", "2022-09-07 17:32:00", "2022-09-15 16:16:00", "2022-09-23 02:12:00", "2022-09-25 00:22:00", "2022-09-25 17:34:00", "2022-09-27 14:42:00", "2022-09-28 15:00:00", "2022-09-29 18:50:00"))
to_dates_1 <- as.POSIXct(c("2021-06-20 00:56:00", "2021-06-22 01:40:00", "2021-07-07 18:14:00", "2021-07-11 12:40:00", "2021-07-31 23:24:00", "2021-08-07 10:56:00", "2021-08-11 09:32:00", "2021-08-13 06:22:00", "2021-08-15 00:24:00", "2021-08-22 21:00:00", "2021-08-27 20:10:00", "2021-09-04 13:38:00", "2021-09-06 11:08:00", "2021-09-13 01:04:00", "2021-09-14 12:56:00", "2021-09-19 12:22:00", "2021-09-22 18:34:00", "2021-09-27 12:08:00", "2022-05-14 02:22:00", "2022-05-17 04:56:00", "2022-05-17 20:56:00", "2022-05-17 22:40:00", "2022-05-20 22:04:00", "2022-05-23 23:12:00", "2022-05-24 07:08:00", "2022-05-24 13:00:00", "2022-05-24 14:42:00", "2022-05-24 16:00:00", "2022-05-25 20:04:00", "2022-05-26 16:20:00", "2022-05-26 21:26:00", "2022-05-29 18:02:00", "2022-05-29 22:06:00", "2022-05-31 00:40:00", "2022-06-09 07:00:00", "2022-06-10 16:46:00", "2022-06-11 15:10:00", "2022-06-11 16:10:00", "2022-06-11 19:16:00", "2022-06-16 21:46:00", "2022-06-17 13:45:00", "2022-06-21 03:18:00", "2022-06-24 00:06:00", "2022-06-24 19:10:00", "2022-06-25 15:24:00", "2022-06-26 16:44:00", "2022-06-27 00:32:00", "2022-06-28 02:26:00", "2022-06-28 16:00:00", "2022-06-30 05:00:00", "2022-06-30 16:58:00", "2022-07-02 12:46:00", "2022-07-06 06:50:00", "2022-07-14 14:30:00", "2022-07-14 18:58:00", "2022-07-15 22:30:00", "2022-07-19 11:28:00", "2022-07-23 17:24:00", "2022-07-23 22:14:00", "2022-07-24 17:12:00", "2022-07-25 00:26:00", "2022-07-25 10:06:00", "2022-07-25 12:18:00", "2022-07-25 16:10:00", "2022-07-30 08:26:00", "2022-07-31 08:12:00", "2022-08-01 18:34:00", "2022-08-02 02:24:00", "2022-08-03 21:04:00", "2022-08-04 05:24:00", "2022-08-14 17:20:00", "2022-08-19 17:10:00", "2022-08-22 08:04:00", "2022-08-25 06:28:00", "2022-08-27 01:15:00", "2022-08-29 14:08:00", "2022-09-03 13:40:00", "2022-09-04 21:04:00", "2022-09-05 07:34:00", "2022-09-07 17:30:00", "2022-09-14 02:28:00", "2022-09-22 11:12:00", "2022-09-25 00:20:00", "2022-09-25 17:32:00", "2022-09-26 05:18:00", "2022-09-27 16:38:00", "2022-09-29 01:06:00", "2022-09-30 10:20:00"))
p_list <-list()
for (i in 1:length(from_dates_1)){
data_subset <- subset(lws_data_10, lws_data_10$TIMESTAMP >= from_dates_1[i] & lws_data_10$TIMESTAMP <= to_dates_1[i])
p <- ggplot(data_subset, aes(x = TIMESTAMP, y = Reference, y = Plant_Shadow))
p_list[[i]] <- p
}
library(gridExtra)
pdf("plots.pdf", onefile = TRUE)
for (i in seq(length(plots))) {
do.call("grid.arrange", p_list[[i]])
}
dev.off()
字符串
1条答案
按热度按时间kgsdhlau1#
在没有包含数据的reprex的情况下,据我所知,问题是第二个
for
循环中的length(plots)
调用。我在代码中没有看到前面称为plots
的对象。你的意思是length(p_list)
吗?替换它应该可以修复它。