I am trying to make ggplot
with more than 10 plots in one graph. However, I realized that my expertise does not work as I noticed the order of legend is not exactly the same as they appear in the figure. Is there any other way to add legend without destroying the structure?
Many many thanks. Below is the code for your reference:
Figure1RCP45 <- ggplot(dataSet1, aes(x = Year)) +
geom_line(aes(y = avgHist, colour = 'HISTORICAL')) +
geom_line(aes(y = ACCESS1, colour = 'ACCESS1')) +
geom_line(aes(y = CANESM21, colour = 'CANESM21')) +
geom_line(aes(y = CAESM1BGC, colour = 'CAESM1BGC')) +
geom_line(aes(y = CCSM4, colour = 'CCSM4')) +
geom_line(aes(y = CMCC_CMS, colour = 'CMCC_CMS')) +
geom_line(aes(y = CNRCCM5, colour = 'CNRCCM5')) +
geom_line(aes(y = GFDL_CM3, colour = 'GFDL_CM3')) +
geom_line(aes(y = HADGECC, colour = 'HADGECC')) +
geom_line(aes(y = HADGEES, colour = 'HADGEES')) +
geom_line(aes(y = MICRO5, colour = 'MICRO5')) +
geom_line(aes(y = avgProj, colour = 'PROJECTED AVERAGE'), size = 1) +
labs(
title = 'First Cycle',
x = 'Year',
y = 'Days to mature',
color = 'Legend\n'
) +
scale_color_manual(
name = 'Legend',
values = c(
'HISTORICAL' = 'black',
'ACCESS1' = 'cyan',
'CANESM21' = 'blue',
'CAESM1BGC' = 'orange',
'CCSM4' = 'yellow',
'CMCC_CMS' = 'green',
'CNRCCM5' = 'red',
'GFDL_CM3' = 'brown',
'HADGECC' = 'gray',
'HADGEES' = 'tomato',
'MICRO5' = 'salmon',
'PROJECTED AVERAGE' = 'magenta'
)
)