ggplot legend: change order of the automatic legend
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order