forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot5.R
More file actions
30 lines (21 loc) · 1.18 KB
/
plot5.R
File metadata and controls
30 lines (21 loc) · 1.18 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
# Exploratory Data Analysis - Assignment 2 - Q. #5
# Ron Mashrouteh May 23, 2014
# Load ggplot2 library
library(ggplot2)
# Loading provided datasets - loading from local machine
NEI <- readRDS("~/Exploratory_Data_Analysis/Assignment_2/summarySCC_PM25.rds")
SCC <- readRDS("~/Exploratory_Data_Analysis/Assignment_2/Source_Classification_Code.rds")
NEI$year <- factor(NEI$year, levels=c('1999', '2002', '2005', '2008'))
# Baltimore City, Maryland == fips
MD.onroad <- subset(NEI, fips == 24510 & type == 'ON-ROAD')
# Aggregate
MD.df <- aggregate(MD.onroad[, 'Emissions'], by=list(MD.onroad$year), sum)
colnames(MD.df) <- c('year', 'Emissions')
# How have emissions from motor vehicle sources changed from 1999-2008 in Baltimore City?
# Generate the graph in the same directory as the source code
png('~/Exploratory_Data_Analysis/Assignment_2/plot5.png')
ggplot(data=MD.df, aes(x=year, y=Emissions)) + geom_bar(aes(fill=year)) + guides(fill=F) +
ggtitle('Total Emissions of Motor Vehicle Sources in Baltimore City, Maryland') +
ylab(expression('PM'[2.5])) + xlab('Year') + theme(legend.position='none') +
geom_text(aes(label=round(Emissions,0), size=1, hjust=0.5, vjust=2))
dev.off()