Question

I have this dataset.

My current R code:

plot(dailyDataCenOF$cenInOFThroughput, type = "l", xaxt = "n", col = "blue",
     main = "Throughput",
     xlab = "Time",
     ylab = "Throughput (Mbps)")
axis(side = 1, at = seq(1, 48, by = 2), labels = 0:23)
par(new = TRUE)
plot(dailyDataCenOF$cenOutOFThroughput, type = "l", xaxt = "n", col = "red",
     axes = F, xlab = NA, ylab = NA)

plots the following: Plot

The result is not what I want to have. Ideally I would like to have the actual time (date is not necessary) from the dataset as X axis labels. I only managed to have 0:23 representing the hours as my X axis labels. I tried to use:

axis(side = 1, at = seq(2, 49, by = 2), labels = 0:23, col = "red")

but the new labels overlap with the previous labels. Even the different color does not make it easy to read.

Of course I can use:

axis(side = 3, at = seq(2, 49, by = 2), labels = 0:23, col = "red")

but I the labels should be at the bottom.

Is there more optimal and/or effective solution for this problem?

Thank you.

Was it helpful?

Solution

Coercion of datetime columns to appropriate objects makes this a little easier.

d <- read.csv('https://dl.dropboxusercontent.com/u/14322966/20140401.csv')
d[, 1] <- as.POSIXct(d[, 1], format='%Y-%m-%d %H:%M:%S')
d[, 3] <- as.POSIXct(d[, 3], format='%Y-%m-%d %H:%M:%S')

xlim <- range(do.call(c,d[c(1,3)]))
plot(d[, 1:2], type='l', xlab='Time', ylab='Throughput (Mbps)', 
     xlim=xlim)
par(new = TRUE)
plot(d[, 3:4], type='l', col=2, axes=F, xlab='', ylab='', 
     xlim=xlim)
axis(4)
box(lwd=2)

Calculation of the range of datetime across the 2 columns allows for consistent xlims across the two plot calls.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top