df$time <- factor(df$time, levels = df$time) library(reshape2) df1 <- melt(df, id.var="time")