forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
15 lines (15 loc) · 1 KB
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Using the read.csv fucntion to import the full dataset
totaldata <- read.csv("C:/Users/dhanush/Desktop/EDA/ExData_Plotting1/household_power_consumption.txt", header=T, sep=';', na.strings="?", nrows=2075259, check.names=F, stringsAsFactors=F, comment.char="", quote='\"')
totaldata$Date <- as.Date(totaldata$Date, format="%d/%m/%Y")
# Subsetting the data for the required date ranges
data <- subset(totaldata, subset=(Date >= "2007-02-01" & Date <= "2007-02-02"))
rm(totaldata)
# converting the date
#using the paste fucntion which converts the arguememnts into strings and conconates them
datetime <- paste(as.Date(data$Date), data$Time)
data$Datetime <- as.POSIXct(datetime)
# Plot 1 is generated using the hist function which is used to generate the histogram of the given data values
hist(data$Global_active_power, main="Global Active Power", xlab="Global Active Power (kilowatts)", ylab="Frequency", col="Red")
# Finally , Saving to file
dev.copy(png, file="plot1.png", height=480, width=480)
dev.off()