forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
24 lines (16 loc) · 950 Bytes
/
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
# set the working directory
setwd("~/MyR/Coursera/EDA/WEEK1")
# set the local to system to english
Sys.setlocale("LC_TIME", "English")
# read all data from file household_power_consumption.txt
df_all <- read.table(unz("exdata%2Fdata%2Fhousehold_power_consumption.zip", "household_power_consumption.txt"), header=TRUE, sep=";")
#df_all <-read.table("household_power_consumption.txt", header = TRUE, sep = ";")
# subset the data from 2007-02-01 to 2007-02-02
df <- subset(df_all, Date == "1/2/2007" | Date == "2/2/2007")
# set the Global_active_power as numeric
df$Global_active_power<-as.numeric(as.character(df$Global_active_power))
# plot the histogram of the Global_active_power, with red color, xlabel and title
hist(df$Global_active_power, col = "red", xlab = "Global Active Power (kilowatts)", main = "Global Active Power")
# save the plot as plot1.png
dev.copy(png,'plot1.png', width=480,height=480)
dev.off()