-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot1Code.R
More file actions
21 lines (16 loc) · 816 Bytes
/
Plot1Code.R
File metadata and controls
21 lines (16 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Read the first 100 rows to get the data types of each column
hpc <- read.table("C:\\Users\\Tim\\Downloads\\household_power_consumption.txt",
sep=";", colClasses=c("character","character",rep("numeric",7)),header=TRUE
,fill=TRUE, na.strings=c("","?","NA"))
#Change date column to a date
hpc$Date<-as.Date(hpc$Date,"%d/%m/%Y")
#Subset the dataset
hpcsub<-subset(hpc,hpc$Date=="2007-02-01"|hpc$Date=="2007-02-02")
#Plot bar chart
#make dimensions 480x480
#add title to chart and label to x-axis
#make tick marks and labels every 200
png(filename = "Plot1.png",width = 480, height = 480)
hist(hpcsub$Global_active_power,col="red", main="Global Active Power", xlab="Global Active Power (kilowatts)")
axis(side=2, at=seq(0,1200, 200), labels=seq(0,1200,200))
dev.off()