1

I made a graph and I want to be able to have lines to show the current day's value in the graph.

Here is my code:

dratio_main <- merge(rolling.dratio.10$Daily, rolling.dratio.21$Daily, rolling.dratio.63$Daily, rolling.dratio.126$Daily, rolling.dratio.252$Daily)
dratio_main <- data.frame(times=time(dratio_main),dratio_main)
names(dratio_main) <- c('Date','D10','D21','D63', 'D126', 'D252')
dratiolatest <- dratio_main[nrow(dratio_main),4:6]

dratiodf <- melt(dratio_main,
                 id.vars = "Date",
                 variable.name = "Type",
                 value.name = "Value")

dratiodf_2 <- filter(dratiodf, Type == c("D63",'D126','D252'))

ggplot(dratiodf_2, aes(x=Value))+
  stat_ecdf(geom = "step")+
  facet_wrap(.~Type)+
  geom_vline(data = dratiolatest,xintercept = dratiolatest,na.rm = T)+
  coord_cartesian(xlim=c(0,4))+
  theme_economist()

Here's part of dratiodf_2:

22  2013-10-24  D63 2.3506257
23  2013-10-29  D63 2.1868155
24  2013-11-01  D63 1.7831371
25  2013-11-06  D63 1.2590704
26  2013-11-11  D63 0.9328020
27  2013-11-14  D63 1.0349820
28  2013-11-19  D63 1.1082279

The idea is that then in later columns you get the same thing but the 'D36' column has changed to another period and the column with the values has changed to different values for that period.

Here is dratiolatest:

               D63      D126      D252
2019-10-01 0.9085238 0.7253774 0.7516055

Those are each period's most recent value.

Now my question is how do I make it so that there are lines in each facet, which show that facet's most recent value?

I have tried various geom_vline and stat_summaryh ideas, and they just won't show up, or show up in the faceted format.

Thank you for your time, regardless of your answering capabilities.

L.Zingg
  • 85
  • 1
  • 10

1 Answers1

0

(If I understoold your problem correctly), with long format of dratiolatest like dratiodf_2 gives what you want.

library(tidyr)

dratiolatest_long <- dratiolatest %>% gather("Type", "Value", -Date)

ggplot(a, aes(x=Value))+
  stat_ecdf(geom = "step")+
  facet_wrap(.~Type)+
  geom_vline(data = dratiolatest_long, aes(xintercept = Value))+  # modified line
  coord_cartesian(xlim=c(0,4))+
  theme_economist()
cuttlefish44
  • 6,586
  • 2
  • 17
  • 34