Here is my data t
time_granularity N V2 V3 V4
1: 2019-03-07 06:00:00 3445 874 1560 2569
2: 2019-03-07 06:15:00 5871 1366 2550 3920
3: 2019-03-07 06:30:00 9790 2157 3831 5615
4: 2019-03-07 06:45:00 13809 3182 5497 8055
5: 2019-03-07 07:00:00 18559 4538 8400 11707
6: 2019-03-07 07:15:00 23563 6015 11256 15620
7: 2019-03-07 07:30:00 28251 7103 14380 19366
8: 2019-03-07 07:45:00 30879 7282 15784 20503
9: 2019-03-07 08:00:00 29575 6968 14208 18269
10: 2019-03-07 08:15:00 26898 5543 11185 14575
Here is the code
p <- ggplot(t, aes(x=time_granularity)) +
geom_bar(aes(y=N), alpha = 1,stat = "identity", fill='lightblue', color='lightblue4') +
geom_bar(aes(y=V4), alpha = 1,stat = "identity", fill="seagreen2", color='forestgreen') +
geom_bar(aes(y=V3), alpha = 1,stat = "identity", fill='yellow1', color='lightyellow4') +
geom_bar(aes(y=V2), alpha = 1,stat = "identity", fill='pink', color='red') +
lims(y = c(0, 32000)) +
scale_x_datetime(
date_breaks = "1 hour",
date_labels = "%H:00")+
xlab("") +
ylab("Count")
I want know how to add the legend and title in this code.I've tried several methods but none of them worked.It would be nice to make a change in my code. enter image description here