I'm trying to figure out how to manipulate the axis labels that are produced when using scale_y_time()
in ggplot2. For example, I would like to change the y-axis label produced by the code below to be just "minutes and seconds" ("%M:%S"
)
Here is a simple example of the kind of plot I am making, with data that represents a "starting point" (start
) and "ending point" (end
) and time tag in seconds that goes with each starting point (time
).
library(tidyverse)
start <- seq(1, 105, 5)
end <- seq(3, 103, 5)
time = seq(0, 360, 18)
dat <- data.frame(start, end, time)
ggplot(dat)
geom_segment(aes(x = start, y = time, xend = end, yend = time))
scale_y_time()
CodePudding user response:
scale_y_time(labels = function(t) strftime(t, "%M:%S"))
should yield: