forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
43 lines (28 loc) · 1.36 KB
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
plot1 <- function ( wd = "C:/f/R/git/ExData_Plotting1", datefrom = "31/1/2007" , dateto = "3/2/2007" ,...)
{
setwd( wd)
directory <- "exdata_data_household_power_consumption"
fn <- "household_power_consumption.txt"
filen <- file.path (directory, fn)
conn <- file ( filen , "r")
data<-read.table (conn , header= TRUE , sep= ";" ,na.strings="?")
close(conn)
#######################################################################
## filter required data
data07 <- data[ as.Date(data$Date ,"%d/%m/%Y") > as.Date(datefrom ,"%d/%m/%Y") &
as.Date(data$Date,"%d/%m/%Y") < as.Date(dateto,"%d/%m/%Y") ,]
Data<- NULL
data07$datetime<- as.POSIXct(strptime(paste(data07$Date, data07$Time), "%d/%m/%Y %H:%M:%S"))
##data$datetime <- paste(data$Date, data$Time)
##data$datetime<- as.Date(strptime(data$datetime,"%d/%m/%Y %H:%M:%S" ))
data07$Global_active_power <- as.numeric( data07$Global_active_power)
#######################################################################
## plot1
par( mfrow = c( 1,1))
RR<- hist(data07$Global_active_power , col="red", xlab ="Global Active Power (Kilowatts)" , main = "Global Active Power" )
## coping output to png file "plot4.png"
dev.copy(png,filename="plot1.png" , height=480, width=480);
dev.off()
return(RR)
}
###########################################################################################################