-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot1.R
38 lines (18 loc) · 885 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Plotting the Histogram:
##
## First we'll source the script that retrieves and packages the data, PowerData.R
source("PowerData.R")
HistogramPlot <- function() {
## Now we'll make the first plot using the histogram function: hist()
## This will involve setting margins with par(), drawing the plot and then
## Copying the plot from the screen device using dev.copy()
PowerData <- PowerData()
## Setting the margins:
par(mar= c(4,4,2,1), bg= "white")
## Drawing the histogrom
hist(PowerData$Global_active_power, col= "red", xlab="Global Active Power (kilowats)", main="Global Active Power")
## Copying the plot to a .png file
dev.copy(png, file= "plot1.png", width= 480, height= 480, units= "px", bg= "white")
## Close connection to the device:
dev.off()
}