Here's a solution using ggplot
along with sample data consisting of only two groups for reasons of clarity. The approach using the levels
argument from the factor
function suggested by Tyler Rinker is absolutely right.
# Required packages
library(ggplot2)
# Initialize RNG
set.seed(10)
# Sample data
df <- data.frame(
grp = as.character(rep(1:2, 24)),
hour = rep(0:23, each = 2),
intensity = runif(2 * 24, min = 0, max = .8)
)
# Plot sample data
ggplot(aes(x = hour, y = intensity, group = grp, colour = grp), data = df) +
geom_line() +
labs(x = "Time [h]", y = "Intensity") +
scale_color_manual("Groups", values = c("1" = "red", "2" = "blue"))
Now, let's adjust the time scale!
# Now, reorder your data according to a given index
index <- c(5:23, 0:4)
df$hour <- factor(df$hour, levels = as.character(index), ordered = T)
# Plot sample data with reordered x-axis
ggplot(aes(x = hour, y = intensity, group = grp, colour = grp), data = df) +
geom_line() +
scale_color_manual("Groups", values = c("1" = "red", "2" = "blue"))
Let me know if it works ;-)