-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot5.R
More file actions
30 lines (22 loc) · 1.13 KB
/
plot5.R
File metadata and controls
30 lines (22 loc) · 1.13 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
#setting Working Directory
setwd("C:/Users/Makarand/Desktop/Coursera/project")
# Load ggplot2 library
require(ggplot2)
# Loading provided datasets from local machine
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("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('plot5.png')
ggplot(data=MD.df, aes(x=year, y=Emissions)) + geom_bar(stat = "identity") + 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()