I'm struggling to get a ggplot chart that includes 2 things:
- a facet-wrap that separates the data into each date
- Keeps the x-axis scale relative to hours and minutes only (HH:MM) , and keeps the x-axis scale between each facet wrap chart the same width as each other. (ie. 10:00 appears in same position on each facet chart)
- the time period of these charts is less than 24hours, only covers 9am - 4pm
Everything I have tried in order to get nice readable labels on the x-axis causes the continuous 'time' variable to have huge gaps within it, which seem to be because dates are also being included behind the scenes.
This is my current code that produces the facet-wrap I need perfectly, but has unreadable x-axis.
ggplot(mydata2, aes(x=time, y=pending, color=server, group=date)) +
geom_point() +
facet_wrap(~ date)
> class(mydata2$time)
[1] "character"
i've tried hms library. but ggplot doesn't seem to know what to do with it.
mydata2$time2 <- lubridate::hms(mydata2$time)
mydata2$time2
[1] "14H 5M 23S" "14H 5M 23S" "14H 5M 42S" "14H 5M 42S" "14H 6M 24S" "14H 6M 24S"
[7] "14H 6M 42S" "14H 6M 42S" .... etc.
But trying to chart this fails, the below just produces a blank chart...
ggplot(mydata2, aes(x=time2, y=pending, color=server, group=tradedate)) +
geom_point() +
facet_wrap(~ tradedate)
Warning messages:
1: Removed 7390 rows containing missing values (geom_point).
How can I achieve the 2 goals listed above?