I've managed to convert date-and-time data for a stockmarket to POSIXct and plot it. But, owing to the fact that markets open and close at specific times, my chart looks awkward with long lines linking the closed periods, below.
I’d like my chart to appear like this, below, whereby the closed periods aren’t visible and the date starts, in this case, on Monday.
I’d appreciate any help in doing this. Here’s my code and some sample data.
hongkongstocks <- read.csv(file="Data/hong-kong-stocks-copy.csv", stringsAsFactors = FALSE)
dateOnlyhongkongstocks <- as.POSIXct(hongkongstocks$Date, format="%m/%d/%y %H:%M" #format time)
ggplot(hongkongstocks, aes(x=dateOnlyhongkongstocks, y=Hang.Seng)) + geom_line()
Sample data
Date Hang.Seng
5/25/20 9:30 100.00
5/25/20 9:35 98.28
5/25/20 9:40 98.46
5/25/20 9:45 99.11
Here's a couple of days of data from the charts above
Date,Hang Seng
5/25/20 9:30,100
5/25/20 9:35,98.28
5/25/20 9:40,98.46
5/25/20 9:45,99.11
5/25/20 9:50,99.74
5/25/20 9:55,100.04
5/25/20 10:00,99.63
5/25/20 10:05,99.77
5/25/20 10:10,99.34
5/25/20 10:20,99.37
5/25/20 10:25,99.06
5/25/20 10:30,99.13
5/25/20 10:40,98.76
5/25/20 10:45,98.72
5/25/20 10:50,98.62
5/25/20 10:55,98.74
5/25/20 11:00,98.64
5/25/20 11:05,98.71
5/25/20 11:10,98.93
5/25/20 11:15,99.23
5/25/20 11:20,98.99
5/25/20 11:30,99.09
5/25/20 11:40,99.02
5/25/20 11:45,99.05
5/25/20 11:50,99.04
5/25/20 12:00,99
5/25/20 13:05,99.24
5/25/20 13:10,99.19
5/25/20 13:15,99.27
5/25/20 13:20,99.32
5/25/20 13:25,99.3
5/25/20 13:30,99.33
5/25/20 13:35,99.49
5/25/20 13:50,99.26
5/25/20 13:55,99.21
5/25/20 14:00,99.35
5/25/20 14:05,99.53
5/25/20 14:10,99.48
5/25/20 14:15,99.51
5/25/20 14:25,99.5
5/25/20 14:30,99.57
5/25/20 14:35,99.61
5/25/20 14:40,99.76
5/25/20 14:45,99.75
5/25/20 14:50,99.83
5/25/20 14:55,99.97
5/25/20 15:00,100.08
5/25/20 15:05,99.96
5/25/20 15:10,99.88
5/25/20 15:15,99.87
5/25/20 15:40,99.94
5/25/20 15:45,99.98
5/25/20 15:50,99.99
5/25/20 15:55,100.06
5/25/20 16:00,100.12
5/25/20 16:05,100.1
5/26/20 9:35,101.41
5/26/20 9:40,101.78
5/26/20 9:45,102.05
5/26/20 9:50,101.83
5/26/20 9:55,101.6
5/26/20 10:00,101.82
5/26/20 10:05,101.77
5/26/20 10:10,101.92
5/26/20 10:15,101.9
5/26/20 10:20,101.98
5/26/20 10:25,101.97
5/26/20 10:40,101.86
5/26/20 10:50,101.61
5/26/20 10:55,101.79
5/26/20 11:00,101.8
5/26/20 11:05,101.93
5/26/20 11:10,101.99
5/26/20 11:15,101.84
5/26/20 11:20,101.74
5/26/20 11:35,101.85
5/26/20 11:40,101.88
5/26/20 11:55,101.94
5/26/20 13:05,102.18
5/26/20 13:10,102.09
5/26/20 13:15,102.01
5/26/20 13:20,102.02
5/26/20 13:30,101.95
5/26/20 13:35,101.96
5/26/20 13:40,102.06
5/26/20 13:45,102.12
5/26/20 13:50,102.1
5/26/20 13:55,102.22
5/26/20 14:00,102.17
5/26/20 14:05,102.26
5/26/20 14:10,102.23
5/26/20 14:20,102.24
5/26/20 14:25,102.27
5/26/20 14:30,102.3
5/26/20 14:35,102.39
5/26/20 14:40,102.36
5/26/20 14:45,102.34
5/26/20 14:50,102.25
5/26/20 15:00,102.21
5/26/20 15:20,102.13
5/26/20 15:45,102.04
5/26/20 15:55,102.14



