forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
34 lines (26 loc) · 1.05 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
# Read header and only read a subset of the data
household_name <- read.csv2(file = "household_power_consumption.txt",
na.strings = "?",
comment.char = "",
stringsAsFactors = FALSE,
nrows = 3)
household <- read.csv2(file = "household_power_consumption.txt",
na.strings = "?",
comment.char = "",
stringsAsFactors = FALSE,
skip = 66637,
nrows = 2879)
names(household) <- names(household_name)
rm(household_name)
#Type convert
household$Global_active_power <- as.numeric(household$Global_active_power)
#Initialize png device as dev.copy seems to have problem
png(filename = 'plot1.png', width = 480, height = 480, units = 'px')
#Plot histrogram
hist(household$Global_active_power, col = "red",
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)")
#Close device to conclude the png
dev.off()
#Some cleaning
rm(household)