forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
48 lines (37 loc) · 1.3 KB
/
plot3.R
File metadata and controls
48 lines (37 loc) · 1.3 KB
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
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
}
createPlot3 <- function()
{
df <- read()
# needed this to switch to english day names in cyrilic r studio
Sys.setlocale("LC_TIME", "English")
plot(df$DateTime, df$Sub_1,
main = "",
ylab="Energy sub metering",
xlab="",
type="l"
)
lines(df$DateTime, df$Sub_2, col="Red")
lines(df$DateTime, df$Sub_3, col="Blue")
legend("topright", lty=1, cex=0.75,
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("Black","Red","Blue"))
dev.copy(png,
res= 60, # had to use res to get rid of legend truncating.
# could be an issue of windows high-dpi display and so on
file="plot3.png")
dev.off()
}