forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
31 lines (17 loc) · 895 Bytes
/
plot1.R
File metadata and controls
31 lines (17 loc) · 895 Bytes
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
# Assignment - 1
# Reads the entire dataset
HOUSEHOLD_data <- read.table("D:\\exploratory_R\\week 1\\household_power_consumption.txt", header = TRUE, sep = ';', na.strings = "?", check.names = FALSE, stringsAsFactors = FALSE, comment.char="", quote='\"')
str(HOUSEHOLD_data)
HOUSEHOLD_data$Date <- as.Date(HOUSEHOLD_data$Date, format="%d/%m/%Y")
# Subseting the required data
data <- subset(HOUSEHOLD_data, subset = (Date >= "2007-02-01" & Date <= "2007-02-02"))
str(data)
# Converts dates
date_time <- paste(as.Date(data$Date), data$Time)
data$Datetime <- as.POSIXct(date_time)
# Ploting Global_active_power
hist(data$Global_active_power, main = "Global Active Power", xlab = "Global Active Power (kilowatts)", ylab = "Frequency", col = "Red")
# Saving the data to file
dev.copy(png, file = "plot1.png", height = 480, width = 480)
dev.off()
dev.off()