Power Bi สร้าง Line Chart ให้แสดงช่วงเวลาที่แกน Y ด้วย R Script
Date |
Start |
Stop |
Threshold |
Total |
1-Jun-20 |
23:10 |
6:52 |
7:00 |
7:42 |
2-Jun-20 |
23:09 |
5:46 |
7:00 |
6:37 |
3-Jun-20 |
23:09 |
3:23 |
7:00 |
4:14 |
4-Jun-20 |
23:07 |
2:44 |
7:00 |
3:37 |
5-Jun-20 |
23:07 |
3:14 |
7:00 |
4:07 |
6-Jun-20 |
23:07 |
4:45 |
7:00 |
5:38 |
7-Jun-20 |
23:07 |
3:48 |
7:00 |
4:41 |
8-Jun-20 |
23:12 |
3:33 |
7:00 |
4:21 |
9-Jun-20 |
23:08 |
3:34 |
7:00 |
4:26 |
library(scales)
library(ggplot2)
Day=format(as.POSIXct(dataset$'Date', format="%Y-%m-%dT%H:%M:%S"), format="%Y-%b-%d")
ggplot(dataset, aes(x = Day , group = 1)) +
geom_linegeom_line(aes(y = as.POSIXct(dataset$'Start', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Start')) +
geom_point(aes(y = as.POSIXct(dataset$'Start', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Start')) +
geom_line(aes(y = as.POSIXct(dataset$'Stop', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Stop')) +
geom_point(aes(y = as.POSIXct(dataset$'Stop', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Stop')) +
geom_line(aes(y = as.POSIXct(dataset$'Threshold', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Threshold'), linetype = 5) +
geom_point(aes(y = as.POSIXct(dataset$'Threshold', format="%Y-%m-%dT%H:%M:%S",tz="UTC"), colour = 'Threshold')) +
scale_y_datetime(limits= c(as.POSIXct('1899-12-31 22:00:00',format='%Y-%m-%d %H:%M:%S',tz="UTC"),
as.POSIXct('1900-01-01 08:00:00',format='%Y-%m-%d %H:%M:%S',tz="UTC"))
,breaks=date_breaks('1 hours'),labels=date_format('%H:%M'))+
xlab("Day") +
ylab("Time") +
labs(colour="Legend") +
theme(axis.text.x=element_text(angle=90))+
theme(axis.text.y=element_text(angle=45))
0 ความคิดเห็น