I have a ggplot2 graph with datetime on the x axis, and categorical on the y axis. I need to put 9 text annotations at certain dates on the x-axis, but there is no space to put the annotations within the graph itself. I want to keep the auto generated dates on the x-axis, and add my custom labels too. I don't care if they're at the top or the bottom.
Synthetic example below. I have 9 events, and lots of activity leading up to these events. I want to put a text label indicating the event name below each event. Eg in this data at Feb 11th at midnight I want to have a label that says "Event 1" somewhere.
events <- data.frame(names=c("Event 1", "Event 2", "Event 3", "Event 4", "Event 5", "Event 6", "Event 7", "Event 8", "Event 9"),
dates=strptime(c("2013-02-10 11:59 pm", "2013-02-21 11:59 pm", "2013-03-02 11:59 pm", "2013-03-16 11:59 pm", "2013-03-26 12:00 pm", "2013-04-11 11:59 pm", "2013-04-24 11:59 pm", "2013-04-23 11:59 pm", "2013-05-08 12:00 pm")
, "%Y-%m-%d %I:%M %p"))
units <- replicate(125, paste(sample(LETTERS, 8), collapse=""))
n <- 2000
df <- data.frame(name=sample(units, n, replace=TRUE),
d=(sample(events$dates, n, replace=TRUE)-rexp(n, 1/150000)),
value=rexp(n, 1/110))
ggplot(data=df, aes(x=d, y=name)) +
geom_point(alpha=I(1/2), aes(size=log(value))) +
ylab("Each row is one unit") +
xlab("Date") +
theme(legend.position="none", legend.direction="horizontal",
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.line.y=element_blank(),
panel.grid.major.y=element_blank(),
panel.grid.minor.y=element_blank())