-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
21 lines (19 loc) · 820 Bytes
/
plot1.R
File metadata and controls
21 lines (19 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# check files
if(!file.exists("Source_Classification_Code.rds") || !file.exists("summarySCC_PM25.rds")){
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2FNEI_data.zip", "exdata-data-NEI_data.zip")
unzip("exdata-data-NEI_data.zip")
}
#Have total emissions from PM2.5 decreased
#in the United States from 1999 to 2008?
#Using the base plotting system,
#make a plot showing the total PM2.5 emission
#from all sources for each of the years 1999, 2002, 2005, and 2008.
generatePlot1<- function(NEI,SCC){
aggr <- aggregate(NEI$Emissions, by=list(NEI$year), FUN=sum)
barplot(aggr$x,beside=FALSE, names = aggr$Group.1, xlab = "Year", ylab= "Total emission")
}
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
png("plot1.png")
generatePlot1(NEI,SCC)
dev.off()