Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Script Name: plot6.R
- ## Version: 1.0_14
- ## Libraries needed:
- library(plyr)
- library(ggplot2)
- library(grid)
- ## Step 1: read in the data
- NEI <- readRDS("expdata_prj2/summarySCC_PM25.rds")
- SCC <- readRDS("expdata_prj2/Source_Classification_Code.rds")
- ## Step 2: check the levels for types of vehicles defined
- mv.sourced <- unique(grep("Vehicles", SCC$EI.Sector, ignore.case = TRUE, value = TRUE))
- mv.sourcec <- SCC[SCC$EI.Sector %in% mv.sourced, ]["SCC"]
- ## Step 3A: subset our data Baltimore City
- emMV.ba <- NEI[NEI$SCC %in% mv.sourcec$SCC & NEI$fips == "24510", ]
- ## Step 3B: subset our data Los Angeles County
- emMV.LA <- NEI[NEI$SCC %in% mv.sourcec$SCC & NEI$fips == "06037", ]
- ## Step 3C: bind the data created in steps 3A and 3B
- emMV.comb <- rbind(emMV.ba, emMV.LA)
- ## Step 4: Find the emmissions due to motor vehicles in
- ## Baltimore (city) and Los Angeles County
- tmveYR.county <- aggregate (Emissions ~ fips * year, data =emMV.comb, FUN = sum )
- tmveYR.county$county <- ifelse(tmveYR.county$fips == "06037", "Los Angeles", "Baltimore")
- ## Step 5: plotting to png
- png("plot6.png", width=750)
- qplot(year, Emissions, data=tmveYR.county, geom="line", color=county) + ggtitle(expression("Motor Vehicle Emission Levels" ~ PM[2.5] ~ " from 1999 to 2008 in Los Angeles County, CA and Baltimore, MD")) + xlab("Year") + ylab(expression("Levels of" ~ PM[2.5] ~ " Emissions"))
- dev.off()
- ##Plot to markdown
- qplot(year, Emissions, data=tmveYR.county, geom="line", color=county) + ggtitle(expression("Motor Vehicle Emission Levels" ~ PM[2.5] ~ " from 1999 to 2008 in Los Angeles County, CA and Baltimore, MD")) + xlab("Year") + ylab(expression("Levels of" ~ PM[2.5] ~ " Emissions"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement