You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
I'm running into a persistent issue around plotting trendlines or treatment lines when the Date is the x-axis.
For example, I'd like to add a vertical line at April 8, as this marks the pre-treatment/post-treatment period. However, when I enter the code below, the treatment line doesn't show up. I'm assuming it's something to do with the date format, but appreciate any advice you have. I've also uploaded my data set if that's helpful. Thanks!
Thanks, Professor. I did take Eric's advice and googled the suggestion (extensively!). I looked at the source you have here, tried it, and it did not make sense to me. I've since figured this out on my own. I thought that the class board was a fine space for us to air questions for you both. Sorry about that.
Yes, these boards reach both of us. Sorry for not responding earlier, weekends get a little challenging for me and communication.
I am curious though, how did you end up solving this issue? One idea I might recommend trying is adding a column to your data for the number of days (1, 2, 3, ...n) And then just use the dates for the labels on the x-axis. That way you could use x=14 or whatever when creating your vertical line.
Hi there,
I'm running into a persistent issue around plotting trendlines or treatment lines when the Date is the x-axis.
For example, I'd like to add a vertical line at April 8, as this marks the pre-treatment/post-treatment period. However, when I enter the code below, the treatment line doesn't show up. I'm assuming it's something to do with the date format, but appreciate any advice you have. I've also uploaded my data set if that's helpful. Thanks!
df$Date <- as.Date( df$Date, '%m/%d')
ggplot(data = df, aes(x = Date, y= MilesWalked)) +
geom_bar(fill="darkseagreen", stat="identity") +
geom_vline(xintercept=04/08,linetype="dashed", color="darkgrey") +
geom_text(x = 04/15, y= 1.1, label="Treatment: Set alarm for 6:15am", color = "darkgrey") +
expand_limits(y=c(0, 1.15)) +
stat_smooth( aes( y = MilesWalked, x = Date), inherit.aes = FALSE, color = "darksalmon") +
xlab("Date") +
ylab("Distance Walked (miles)") +
ggtitle("Distance Walked Before 7am") +
theme(
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "darkgrey")
) +
theme(plot.title = element_text(hjust = 0.5))
The text was updated successfully, but these errors were encountered: