Good evening everybody, The data are:
Data X Y
01/01/16 17073 229
01/02/16 16094 375
01/03/16 17380 880
01/04/16 19993 9978
01/05/16 26290 24782
01/06/16 32982 36437
01/07/16 38490 42547
01/08/16 36688 43928
01/09/16 22799 36734
01/10/16 15000 11816
01/11/16 10494 680
01/12/16 10944 434
01/01/17 17217 235
01/02/17 15501 466
01/03/17 19236 1608
01/04/17 22239 8490
01/05/17 30390 23374
01/06/17 35579 34568
01/07/17 39613 43283
01/08/17 44089 44741
01/09/17 25542 35611
01/10/17 16357 10131
01/11/17 11754 541
02/12/17 11583 362
I have a little problem with my chart.
I wrote this code:
ggplot()
+ geom_line(data=DB_Reg, aes(x=DB_Reg$Data,
y=DB_Reg$X), color='435',size=0.5, show.legend = TRUE)+
geom_line(data=DB_Reg, aes(x=DB_Reg$Data, y=DB_Reg$Y),color='534',size=0.5, show.legend = TRUE)+
ggtitle("XY")+
xlab("Dates")+
ylab("Quantity")+
geom_point()
I'd like to put the legend about the two lines. I wrote show.legend=TRUE for the two lines, but doesn't work.
When using ggplot
it is very important to ensure the code is written in the correct order. For example, adding geom_point()
at the end is going to overwrite the previous argument. Try removing it. Here is a script that should work.
ggplot(data=DB_Reg)+
geom_line(mapping=aes(y=X,x= Data,color="X"),size=1 ) +
geom_line(mapping=aes(y=Y,x= Data,color="Y"),size=1) +
scale_color_manual(values = c(
'X' = 'darkblue',
'Y' = 'red')) +
labs(color = 'Y series')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments