forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
57 lines (37 loc) · 1.4 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
cullfat <- function(){
df <- read.table("./household_power_consumption.txt",
header = TRUE,
sep = ";",
colClasses = "character",
na.strings = "?")
df.sub <- subset(df, Date == "1/2/2007" | Date == "2/2/2007")
write.csv(df.sub, file = "data.csv")
rm(df)
}
makeTimestamp <- function(){
# Creates a nicely formatted "timestamp field to replace "Date" and "Time"
df <- read.csv("./data.csv")
df$timestamp <- paste(df$Date, df$Time)
# remove unnecesary columns
df$Date <- NULL
df$Time <- NULL
#View(df)
write.csv(df, file = "data1.csv")
}
plot1 <- function(){
# cullfat() #run once to create smaller csv file
# makeTimestamp() # run once to format Date-Time
df <- read.csv("./data.csv")
df.sub <- df[,"Global_active_power"]
png(filename = "plot1.png",
width = 480, height = 480, units = "px", pointsize = 12,
bg = "white", res = NA,
type = "quartz")
hist(df.sub,
breaks = 12,
freq = TRUE,
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)",
col = "red", border = "black")
dev.off()
}