-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
31 lines (22 loc) · 1.01 KB
/
plot1.R
File metadata and controls
31 lines (22 loc) · 1.01 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
# 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.
NEI.file <- "summarySCC_PM25.rds"
SCC.file <- "Source_Classification_Code.rds"
message(paste("Reading ", NEI.file, " dataset"))
NEI <- readRDS(NEI.file)
message(paste("Reading ", SCC.file, " dataset"))
SCC <- readRDS(SCC.file)
message("Calculating yearly total emissions")
NEI.total <- aggregate(list(emissions = NEI$Emissions), by=list(year = NEI$year), FUN = sum)
message("Plotting and saving file")
par(mar=c(5,5,6,3))
barplot((NEI.total$emissions/1000),
ylim=c(0, 8000),
names.arg = c(as.character(NEI.total$year)),
col="red",
xlab = "Years",
ylab="PM2.5 Emissions (per 1000 tons)")
mtext(side=3, line=3, "PM2.5 Emissions in United States between 1999 and 2008", cex=1.2)
dev.copy(png, file = "plot1.png", width = 580, height = 580)
dev.off()