i couldn't find way looking similar question @ here geom-vline-with-character-xintercept.
basically, try add vertical lines x values , vertical lines positions can assigned levels(thedf$yrqtr)[c(t, rep(f, 2))]
code.
but getting error shown below. couldn't find out.
reproducible example code;
thegrid <- expand.grid(2009:2011, 1:4) thedf <- data.frame(yrqtr=sprintf("%s q%s", thegrid$var1, thegrid$var2), minutes=c(1000, 2200, 1450, 1825, 1970, 1770, 1640, 1920, 1790, 1800, 1750, 1600)) ggplot(thedf, aes(x=yrqtr, y=minutes)) + geom_point() + theme(axis.text.x=element_text(angle=90))+ geom_vline(aes(xintercept = levels(thedf$yrqtr)[c(t, rep(f, 2))]))
error: aesthetics must either length 1 or same data (12): xintercept
first, don't have use aes
geom_vline
. need provide values. second, ggplot
transform character variable numeric when producing plot. hence, need transform value well. can adding seq_along
. implicitly changes character numeric values (1, 2, 3...).
ggplot(thedf, aes(x=yrqtr, y=minutes)) + geom_point() + theme(axis.text.x=element_text(angle=90))+ geom_vline(xintercept=seq_along(levels(thedf$yrqtr))[c(t, rep(f, 2))])