我第一次使用Anomalize程序包,并且遇到绘制多个图形的问题,我的参考是下一页1 这是我的代码:
library(tidyr)
library(dplyr)
library(anomalize) #tidy anomaly detection
library(tibbletime)
head(mydata,3)
till_id timestamp source_data sda_tps sda_rd_sec/s sda_wr_sec/s
sda_avgrq-sz sda_avgqu-sz sda_await sda_svctm sda_%util
1 s0992-t03 2019-01-22 09:03:01 disk 2.59 49.73
29.82 30.76 0.01 4.47 0.60 0.15
2 s0992-t03 2019-01-22 09:04:01 disk 0.81 0.00
9.59 11.85 0.00 5.4 0.90 0.07
# Convert datetime column as Posixct
mydata$timestamp <- strptime(mydata$timestamp, tz="UTC", "%Y-%m-%dT%H:%M:%SZ")
mydata$timestamp <- as.POSIXct(mydata$timestamp)
df1 <- mydata %>%
dplyr::select(timestamp, sdatps, `sdardsec/s`, `sdawrsec/s`,
`sdaavgrq-sz`,`sdaavgqusz`, sdaawait, sdasvctm, `sda%util`) %>%
gather(key = "variable", value = "value", -timestamp) %>% arrange(timestamp)
df1 <- as_tbl_time(df1, timestamp)
# A time tibble: 2,904 x 3
# Index: timestamp
timestamp variable value
<dttm> <chr> <dbl>
1 2019-01-22 09:03:01 sdatps 2.59
2 2019-01-22 09:03:01 sdardsec/s 49.7
3 2019-01-22 09:03:01 sdawrsec/s 29.8
4 2019-01-22 09:03:01 sdaavgrq-sz 30.8
5 2019-01-22 09:03:01 sdaavgqu-sz 0.01
df1 %>%
# Data Manipulation / Anomaly Detection
time_decompose(value, method = "stl") %>%
anomalize(remainder, method = "iqr") %>%
time_recompose() %>%
# Anomaly Visualization
plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.25) +
labs(title = "Anomalies", subtitle = "STL + IQR Methods")
Anomalies plot 您能帮我理解我在做什么,以便只得到一个图而不是8个图吗?
在此先感谢您的帮助