I'm trying to use facet_wrap to plot a bunch of dataset as scatterpoints, each with an individual line in them indicating when a specific event happened. However, I haven't been able to get the lines to show up individually in each plot, but rather they all show up in all of the plots. After melting, the data looks like:
names(data) = c("Date","ID", "event_date", "variable", "value")
where I want each plot to be a scatter plot of value ~ Date, and each plot divided up by ID with a vertical line appearing at each "event_date" that shows up for each ID. My best efforts have gotten me to:
p <- qplot(Date, value, data=dat, colour=variable)
p <- p + geom_vline(xintercept=as.numeric(dat$event_date))
p + facet_wrap(~ID)
Which works perfectly except for all of the vertical lines showing up in every subplot. Any suggestions? Reading through the documentation hasn't gotten me anywhere yet.
ggplot(dat, aes(Date,value))+ geom_point() + geom_vline(data=dat,aes(xintercept=as.numeric(event_date))) + facet_wrap(~ID)
Is how I do the same thing using facet_grid(). I'm pretty sure it will work for facet_wrap as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With