Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. ## Script Name: plot6.R
  2. ## Version: 1.0_14
  3.  
  4. ## Libraries needed:
  5. library(plyr)
  6. library(ggplot2)
  7. library(grid)
  8.  
  9. ## Step 1: read in the data
  10. NEI <- readRDS("expdata_prj2/summarySCC_PM25.rds")
  11. SCC <- readRDS("expdata_prj2/Source_Classification_Code.rds")
  12.  
  13. ## Step 2: check the levels for types of vehicles defined
  14. mv.sourced <- unique(grep("Vehicles", SCC$EI.Sector, ignore.case = TRUE, value = TRUE))
  15.  
  16. mv.sourcec <- SCC[SCC$EI.Sector %in% mv.sourced, ]["SCC"]
  17.  
  18.  
  19. ## Step 3A: subset our data Baltimore City
  20. emMV.ba <- NEI[NEI$SCC %in% mv.sourcec$SCC & NEI$fips == "24510", ]
  21. ## Step 3B: subset our data Los Angeles County
  22. emMV.LA <- NEI[NEI$SCC %in% mv.sourcec$SCC & NEI$fips == "06037", ]
  23.  
  24. ## Step 3C: bind the data created in steps 3A and 3B
  25. emMV.comb <- rbind(emMV.ba, emMV.LA)
  26.  
  27. ## Step 4: Find the emmissions due to motor vehicles in
  28. ## Baltimore (city) and Los Angeles County
  29. tmveYR.county <- aggregate (Emissions ~ fips * year, data =emMV.comb, FUN = sum )
  30. tmveYR.county$county <- ifelse(tmveYR.county$fips == "06037", "Los Angeles", "Baltimore")
  31.  
  32. ## Step 5: plotting to png
  33. png("plot6.png", width=750)
  34. 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"))
  35. dev.off()
  36.  
  37. ##Plot to markdown
  38. 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