Last active
December 24, 2015 01:19
-
-
Save nacnudus/6723265 to your computer and use it in GitHub Desktop.
ggplot axis time format HH:mm:ss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timeHMS_formatter <- function(x) { | |
x[is.na(x)] <- 0 | |
h <- trunc(x * 24) | |
m <- trunc(x * 24 * 60) | |
s <- x * 24 * 60 * 60 %% 60 | |
s <- round(s, 2) | |
lab <- sprintf('%02d:%02d:%02d', h, m, s) # Format the strings as HH:MM:SS | |
lab <- gsub('^00:', '', lab) # Remove leading 00: if present | |
lab <- gsub('^0', '', lab) # Remove leading 0 if present | |
} | |
# use it like | |
yourPlot + scale_y_continuous(label=timeHMS_formatter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment