You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, a student asked about changing the order of x-axis labels to show a complete diurnal cycle. The original plot started at midnight and went to midnight. This cut the cycle in half. Ideally, the cycle will start at 6am and cycle 24 hours. One option would be to renumber the hours; however, we should label time with the correct hours for interpretation. It is illustrated here with synthetic data in a reproducible example.
library(ggplot2)
tim <- c(0:23)
dat <- sin(seq(from=0, to=6.3, by=0.27))
dat2 <- cos(seq(from=0, to=6.3, by=0.27))
lab <- as.character(tim)
ord <- c(19,20,21,22,23,24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
Normally, we would show this in a simple plot, plot(tim,dat). Or, in ggplot2:
This produces a sequence that starts and ends at midnight. Instead of keeping a simple time and data set, we added two additional variables, lab for labels and ord for order. We include this in a data frame for use in ggplot. Because of the order, we have moved the plot to start and stop at 6am.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Recently, a student asked about changing the order of x-axis labels to show a complete diurnal cycle. The original plot started at midnight and went to midnight. This cut the cycle in half. Ideally, the cycle will start at 6am and cycle 24 hours. One option would be to renumber the hours; however, we should label time with the correct hours for interpretation. It is illustrated here with synthetic data in a reproducible example.
Normally, we would show this in a simple plot,
plot(tim,dat)
. Or, in ggplot2:This produces a sequence that starts and ends at midnight. Instead of keeping a simple time and data set, we added two additional variables, lab for labels and ord for order. We include this in a data frame for use in ggplot. Because of the order, we have moved the plot to start and stop at 6am.
Beta Was this translation helpful? Give feedback.
All reactions