How do I abbreviate ggplot's horizontal grid lines after extending the range of the horizontal axis? I am extending the range in order to display geom_text elements.
I want to make the horizontal grid lines in my line graph disappear after x >= 2014. I am using geom_text to label one of the geom_lines. Is this possible, or is extending the range the wrong approach to begin with?
Here is how I create the plot:
library(quantmod)
library(plyr)
library(ggplot2)
abblist <- list(CA="California",IL="Illinois",TX="Texas",NY="New York")
cleandata <- function(thelist,i) {
abbname <- names(thelist)[[i]]
fullname <- thelist[[i]]
seriesname <- paste(abbname, "UR", sep = "")
df <- apply.yearly(getSymbols(seriesname,src='FRED',auto.assign=F),mean)
df <- data.frame(year=time(df),coredata(df))
df$year <- as.numeric(format(df$year, "%Y"))
names(df)[names(df)==seriesname] <- "urate"
df$state <- as.factor(fullname)
df
}
urates <- rbind.fill(lapply(seq_along(abblist), cleandata, thelist=abblist))
mytheme <- theme_grey() +
theme(
panel.background = element_rect(fill="white"),
legend.position="none",
axis.title.x = element_blank(),
axis.title.y = element_blank()
)
p <- ggplot(urates, aes(x=year, y=urate)) +
geom_line(data=subset(urates,state!="New York"), aes(group=state), color="grey") +
geom_line(data=subset(urates,state=="New York"), color="maroon") +
geom_text(data=subset(urates,year==max(year) & state == "New York"), aes(label=state,x=year+0.25), hjust=0, color="grey20", size=3) +
mytheme +
scale_x_continuous(limits=c(2000,2015),breaks=seq(2000,2014,2),minor_breaks=seq(2001,2013,2))