-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot2.R
More file actions
28 lines (21 loc) · 749 Bytes
/
plot2.R
File metadata and controls
28 lines (21 loc) · 749 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
#download data and save to "Data" folder
fileUrl <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2FNEI_data.zip"
zipFile <- "pm25 emissions.zip"
if (!file.exists(zipFile)) {
download.file(fileUrl, zipFile, mode = "wb")
}
data <- "Data"
if (!file.exists(data)) {
unzip(zipFile)
}
#read files
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
#subset NEI for Baltimore
baltimore <- subset(NEI, fips=="24510")
#get total sum of emissions for Baltimore by year
balt_emissions <- tapply(baltimore$Emissions, baltimore$year, sum)
#plot
png("plot2.png")
barplot(balt_emissions, xlab="Year", ylab="PM2.5 Emissions (tons)", main="Total PM2.5 Emissions in Baltimore by Year", ylim=c(0, 3500))
dev.off()