forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
37 lines (29 loc) · 949 Bytes
/
plot2.R
File metadata and controls
37 lines (29 loc) · 949 Bytes
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
read <- function()
{
fn <- "household_power_consumption.txt"
df <- read.csv(fn,
as.is = T,
dec = '.',
sep = ";",
na.strings = "?",
skip = 66636,
nrows = 2880,
col.names = c("Date","Time", "Global_AC", "Global_RC", "V", "Global_Int","Sub_1","Sub_2", "Sub_3"),
colClasses = c("character", "character", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric"))
df$DateTime <- strptime(paste(df$Date, df$Time),"%d/%m/%Y %H:%M:%S")
df
}
createPlot2 <- function()
{
df <- read()
# needed this to switch to english day names in cyrilic r studio
Sys.setlocale("LC_TIME", "English")
plot(df$DateTime, df$Global_AC,
main = "",
ylab="Global Active Power (kilowatts)",
xlab="",
type="l"
)
dev.copy(png, file="plot2.png")
dev.off()
}