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
23 lines (19 loc) · 1.14 KB
/
plot1.R
File metadata and controls
23 lines (19 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Plot Global Active power distribution from 2007-02-01 to 2007-02-02
plot1 <- function() {
#Read input data
print("Loading file")
pwr_part <- read.table("household_power_consumption.txt", header=TRUE,na.strings="?", comment.char="", stringsAsFactors = FALSE,sep = ";",nrow=5)
detTypes <- sapply(pwr_part, class)
pwr_full <- read.table("household_power_consumption.txt", header=TRUE,na.strings="?", comment.char="", stringsAsFactors = FALSE,sep = ";", colClasses=detTypes)
pwr_full$Date <- as.Date(pwr_full$Date, format="%d/%m/%Y")
pwr <- subset(pwr_full, (pwr_full$Date >= "2007-02-01") & (pwr_full$Date <= "2007-02-02"))
print("Plotting")
#The following command is platform-specific,
# it is used to ensure a new window in case running multiple plot scripts in the same session
#If running on another platform (non-Unix) adapt or just remove it
x11() #Note: platform-specific
hist(pwr$Global_active_power, main="Global Active power", col="blue",xlab="Global active power (kW)", ylab="Frequency")
print(paste("Selected rows:" , nrow(pwr), "/", nrow(pwr_full)))
dev.copy(png, file="plot1.png",width=480,height=480)
dev.off()
}