1

Slightly bizarre request, I know, but bear with me.

I have an Excel spreadsheet with some logging data taken from a highly parallelised bit of server-side code. I'm trying to analyse it for where there may be gaps in the logs, indicating tasks that should be logged but aren't; but because it's a serial, timestamp-order list of a dozen or so parallel threads it's quite hard to read. So I had the unorthodox idea of using a Gantt chart to visualise the overlapping tasks. Excel is terrible at this, so I started looking at alternative tools, and I thought of trying R.

Each task in the log has a start timestamp, and end timestamp, and a duration, so I have the data that I need. I read this SO post and mutilated the example into this R script:

tasks <- c("Task1", "Task2")
dfr <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = c("07/08/2013 09:03:25.815", "07/08/2013 09:03:25.956"),
  end.date    = c("07/08/2013 09:03:28.300", "07/08/2013 09:03:30.409"),
  is.critical = c(TRUE, TRUE)
)

mdfr <- melt(dfr, measure.vars = c("start.date", "end.date"))

ggplot(mdfr, aes(as.Date(value, "%d/%m/%Y %H:%M:%OS"), name, colour = is.critical)) + 
  geom_line(size = 6) +
  xlab("") + ylab("") +
  theme_bw()

This doesn't work, though -- it doesn't plot any data, and the time axis is all messed up. I suspect (unsurprisingly) that plotting sub-second Gantt charts is a weird thing to do. I'm a complete R newbie (although I've been looking for an excuse to try it out for ages) -- is there any simple way to make this work?

Community
  • 1
  • 1
Richard Gaywood
  • 199
  • 1
  • 9

1 Answers1

1

First, your time should be in POSIXct format not Date as it contains also hours and minutes. You can add new column to your melted dataframe with correct format.

mdfr$time<-as.POSIXct(strptime(mdfr$value, "%d/%m/%Y %H:%M:%OS"))

Then with scale_x_datetime() you can control where the breaks will be on axis. For the x values use new column with correct format.

library(scales)
ggplot(mdfr, aes(time,name, colour = is.critical)) + 
  geom_line(size = 6) +
  xlab("") + ylab("") +
  theme_bw()+
  scale_x_datetime(breaks=date_breaks("2 sec"))
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201