forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
32 lines (24 loc) · 1.37 KB
/
plot3.R
File metadata and controls
32 lines (24 loc) · 1.37 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
32
# Exploratory Data Analysis - Assignment 2 - Q. #3
# Ron Mashrouteh May 23, 2014
# Load ggplot2 library
require(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")
# Sampling
NEI_sampling <- NEI[sample(nrow(NEI), size=5000, replace=F), ]
# Baltimore City, Maryland == fips
MD <- subset(NEI, fips == 24510)
MD$year <- factor(MD$year, levels=c('1999', '2002', '2005', '2008'))
# Of the four types of sources indicated by the type (point, nonpoint, onroad, nonroad) variable,
# which of these four sources have seen decreases in emissions from 1999–2008 for Baltimore City?
# Which have seen increases in emissions from 1999–2008?
# Use the ggplot2 plotting system to make a plot answer this question.
# Generate the graph in the same directory as the source code
png(filename='~/Exploratory_Data_Analysis/Assignment_2/plot3.png', width=800, height=500, units='px')
ggplot(data=MD, aes(x=year, y=log(Emissions))) + facet_grid(. ~ type) + guides(fill=F) +
geom_boxplot(aes(fill=type)) + stat_boxplot(geom ='errorbar') +
ylab(expression(paste('Log', ' of PM'[2.5], ' Emissions'))) + xlab('Year') +
ggtitle('Emissions per Type in Baltimore City, Maryland') +
geom_jitter(alpha=0.10)
dev.off()