0

I have a continuous y-axis that needs values relabelled into time on a 12-hour AM/PM clock. I would prefer not to change the actual variable into time because that would make the statistics exceedingly difficult. Currently, time on my graph is measured in hours since the previous midnight.

For example:

22 = 10pm

25 = 1am

28 = 4am

My current ggplot graphing code is:

ggplot(fwb_merged1, aes(x = age, y = midslp, color = fhr)) +
  geom_point(shape = 20, alpha = 0.35) + 
  scale_color_manual(name="Family High Risk Status",
                       labels=c("Control","Family High Risk"),
                       values=c("#5a9abf","#EB515E")) +
  geom_smooth(method = "lm", fill = NA) +
  ggtitle("Sleep Midpoint vs Age by FHR") +
  xlab ("Age") + ylab("Sleep Midpoint (Hours since Previous Midnight)")

How can I modify this code to allow me to either manually change the values on the y axis or transpose my current values into time for the graph?

  • 3
    (1) `scale_y_continuous` has arguments `breaks=` and `labels=` for needs like this. (2) *"make the statistics exceedingly difficult'* ... no idea what you mean, but if you can resolve how to do statistics given real `POSIXt` values, then you could more easily use `scale_y_datetime(date_labels="HH:MM")` or similar. (3) Sample data would greatly inform this and increase the odds of you getting a fast and accurate answer, please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Apr 20 '22 at 17:28

0 Answers0