Kshitij Sambhare Kshitij Sambhare - 1 month ago 9
R Question

Line chart for multiple Variables

Following is my dataset:

MONTH YEAR Load
6 2011 5224.055
7 2011 6073.028
8 2011 5261.029
9 2011 4769.155
6 2012 4865.499
7 2012 5797.578
8 2012 5433.050
9 2012 4482.148
6 2013 4922.000
7 2013 5808.981
8 2013 4928.632
9 2013 4395.204
6 2014 4819.491
7 2014 5258.155
8 2014 4786.323
9 2014 4468.914
6 2015 4931.468
7 2015 5403.063
8 2015 5266.076
9 2015 4803.703


Now I want LOAD on Y-axis, Year on X-axis and line should depict the load and year variation for each month. Separate line for separate month

Answer

Using ggplot2 (plus dplyr to convert month numbers to month names on the fly), it would be something like this (and we'll assume your data frame is called dat):

library(dplyr)
library(ggplot2)

ggplot(dat %>% mutate(MONTH=factor(month.abb[MONTH], levels=month.abb)), 
       aes(x=YEAR, y=Load, colour=MONTH)) + 
  geom_line() +
  geom_point() +
  theme_bw() +
  scale_y_continuous(limits=c(0,6500)) +
  labs(colour="Month")

enter image description here