Hi, I would like to plot a ts line graph showing maximum and minimum temperature on y1 axis and rainfall on y2 axis. I tried to load the csv file and convert date value but it still returns a character. Some help with this please. Here is my script:
library(ggplot2)
library(lubridate)
setwd("D:/R_scrips")
data<-read.csv("D:/R_scrips/temp_rain.csv", header=T, stringsAsFactors = FALSE)
head(data)
date max_temp min_temp rainfall
1 Jan-80 33.1 19.4 45
2 Feb-80 33.0 19.8 67
3 Mar-80 31.5 19.2 209
4 Apr-80 30.6 19.1 180
5 May-80 28.9 18.7 131
6 Jun-80 28.8 18.4 115
as.Date(data$date,format="%d-%b-%y")
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
str(data)
'data.frame': 24 obs. of 4 variables:
date : chr "Jan-80" "Feb-80" "Mar-80" "Apr-80" ... max_temp: num 33.1 33 31.5 30.6 28.9 28.8 27.9 29.2 30.9 30.6 ...
min_temp: num 19.4 19.8 19.2 19.1 18.7 18.4 17.6 17.7 17.9 18.2 ... rainfall: int 45 67 209 180 131 115 104 184 133 121 ...
data
date max_temp min_temp rainfall
1 Jan-80 33.1 19.4 45
2 Feb-80 33.0 19.8 67
3 Mar-80 31.5 19.2 209
4 Apr-80 30.6 19.1 180
5 May-80 28.9 18.7 131
6 Jun-80 28.8 18.4 115
7 Jul-80 27.9 17.6 104
8 Aug-80 29.2 17.7 184
9 Sep-80 30.9 17.9 133
10 Oct-80 30.6 18.2 121
11 Nov-80 29.8 17.9 80
12 Dec-80 31.5 18.6 36
13 Jan-81 33.4 18.3 43
14 Feb-81 34.4 17.7 38
15 Mar-81 29.6 17.8 101
16 Apr-81 28.5 19.4 193
17 May-81 28.7 18.0 208
18 Jun-81 29.3 17.6 79
19 Jul-81 28.1 17.8 81
20 Aug-81 27.9 17.8 94
21 Sep-81 29.6 17.6 109
22 Oct-81 30.5 18.0 189
23 Nov-81 30.1 17.9 156
24 Dec-81 31.7 18.2 35