-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
34 lines (25 loc) · 1.09 KB
/
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
# load required packages
library(package = RMySQL)
# Set working directory
setwd("~/Dropbox/Coursera/ExData_Plotting2/")
# Check if data directory exists and if not, create one
if(!file.exists("data")){
dir.create("data")
}
# Loading provided datasets - loading from local machine
NEI <- readRDS("./data/summarySCC_PM25.rds")
SCC <- readRDS("./data/Source_Classification_Code.rds")
# Sampling
NEI_sampling <- NEI[sample(nrow(NEI), size=2000, replace=F), ]
# Aggregate
Emissions <- aggregate(NEI[, 'Emissions'], by=list(NEI$year), FUN=sum)
Emissions$PM <- round(Emissions[,2]/1000,2)
# 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.
# Generate the graph in the same directory as the source code
png(filename='plot1.png')
barplot(Emissions$PM, names.arg=Emissions$Group.1,
main=expression('Total Emission of PM'[2.5]),
xlab='Year', ylab=expression(paste('PM', ''[2.5], ' in Kilotons')))
dev.off()