Начиная с ваших данных в длинной форме. Просто нужно было использовать функцию scale_colour_manual( )
для добавления нужного цвета к диаграмме.
data<-structure(list(No. = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L), group = c("s1", "s2", "s3", "s4", "s1", "s2", "s3",
"s4", "s1", "s2", "s3", "s4", "s1", "s2", "s3", "s4", "s1", "s2",
"s3", "s4", "s1", "s2", "s3", "s4", "s1", "s2", "s3", "s4"),
Data = c(0.52, 0.25, 0.03, 0.12, 0.32, 0.45, 0.12, 0.98,
0.46, 0.48, 0.52, 0.82, 0.25, 0.47, 0.24, 0.5, 0.09, 0.53,
0.85, 0.41, 0.98, 0.02, 0.72, 0.35, 0.54, 0.91, 0.63, 0.65
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -28L))
labels <- c("group1", "group2", "group3", "group4")
title<-"Legend"
ggplot(data, aes(x=No., y=Data, colour=group, alpha=group, size=group))+
geom_line() +
xlab("Number")+ylab("length")+
theme(legend.position="bottom")+
scale_colour_manual(values=c("s1" = "red", "s2"= "firebrick", s3="orange", s4="darkolivegreen"), labels = labels) +
scale_alpha_manual(values=c(1,0.4,0.4,1), labels = labels)+
scale_size_manual(values=c(4,1,1,4), labels = labels) +
guides(colour = guide_legend(title = title),
alpha = guide_legend(title = title),
size = guide_legend(title = title))