Source: https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2FNEI_data.zip
Here is my data prep.
NEI <- readRDS("summarySCC_PM25.rds")
Baltimore <- NEI[NEI$fips=="24510", ]
Baltimore$type <- as.factor(Baltimore$type)
Total_Emmisssions <- aggregate(Baltimore$Emissions,
by=list(Baltimore$year, Baltimore$type),
FUN=sum)
names(Total_Emmisssions) <- c("Year","Type","Emissions")
Plot code
library(ggplot2)
g <- ggplot(Total_Emmisssions,aes(x=Year, y=Emissions, colour=Type))
g1 <- g+geom_point()
g2 <- g1+facet_grid(. ~ Type)
g3 <- g2+geom_smooth(method="lm", se=FALSE)
However, in this plot, the year is always 2002-2008. How do I change the scale / ticks to show from 1999-2008 at an interval of 3 years. Using scale_x_discrete
does not work and it messes the graph. Please help.
str(Total_Emmisssions)
'data.frame': 16 obs. of 3 variables:
$ Year : int 1999 2002 2005 2008 1999 2002 2005 2008 1999 2002 ...
$ Type : Factor w/ 4 levels "NON-ROAD","NONPOINT",..: 1 1 1 1 2 2 2 2 3 3 ...
$ Emissions: num 522.9 240.8 248.9 55.8 2107.6 ...