Am currently learning R and I would like to plot a graph which looks like this:
I have monthly data for data for three years and I would like all the months to be labeled on the x axis. this is what I tried out so far and the error message I received. Thanks for the help
library(ggplot2)
library(lubridate)
setwd("D:/R_scrips")
data1<- read.csv("D:/R_scrips/srf.csv", header=T, stringsAsFactors = FALSE)
data1
Date Rainfall
1 Jan-09 3.1
2 Feb-09 0.2
3 Mar-09 1.2
4 Apr-09 4.1
5 May-09 3.5
6 Jun-09 1.2
7 Jul-09 2.7
8 Aug-09 6.1
9 Sep-09 6.4
10 Oct-09 5.7
11 Nov-09 3.1
12 Dec-09 5.1
13 Jan-10 1.8
14 Feb-10 3.4
15 Mar-10 7.5
16 Apr-10 3.2
17 May-10 7.3
18 Jun-10 6.4
19 Jul-10 6.8
20 Aug-10 3.9
21 Sep-10 3.9
22 Oct-10 6.6
23 Nov-10 1.4
24 Dec-10 0.6
25 Jan-11 0.7
26 Feb-11 0.3
27 Mar-11 3.2
28 Apr-11 3.2
29 May-11 4.9
30 Jun-11 2.8
31 Jul-11 3.8
32 Aug-11 10.0
33 Sep-11 5.6
34 Oct-11 5.6
35 Nov-11 3.9
36 Dec-11 1.3
str(data1)
'data.frame': 36 obs. of 2 variables:
Date : chr "Jan-09" "Feb-09" "Mar-09" "Apr-09" ... Rainfall: num 3.1 0.2 1.2 4.1 3.5 1.2 2.7 6.1 6.4 5.7 ...
data1$Date <- as.Date(as.character(data1$Date), format="d%-%b-%y")
str(data1)
'data.frame': 36 obs. of 2 variables:
Date : Date, format: NA NA NA NA ... Rainfall: num 3.1 0.2 1.2 4.1 3.5 1.2 2.7 6.1 6.4 5.7 ...
ggplot(data1, aes(Time, Rainfall, group = 1)) +
- geom_line()
Error in FUN(X[[i]], ...) : object 'Time' not found
ggplot(data1, aes(Date, Rainfall, group = 1)) +
- geom_line()
Error in seq.int(0, to0 - from, by) : 'to' must be a finite number