-1

My plot is displaying weird numbers instead of dates. When converting them I find today's date. The issue is that I'm studying past dates. I would like to display on the chart below, the dates corresponding to the values.

enter image description here

This is the Data Frame: enter image description here

I already converted dates using:

dates <- lubridate::mdy(rv_data_USDC_DAILY$Date)

This is my code for the plot:

par(mfrow = c(1, 2))
plot.ts(x=df_peg$date, y=df_peg$BUSDPEG, type="l", main = "", col="#1F4690", ylab="USD")
abline(h=0)
mtext("BUSD Deviations from Peg")
hist(df_peg$BUSDPEG, xlim = c(-0.01,0.01), main="", col="#D61C4E")

Sample of Data:

         date       BUSDPEG  USDCPEG        DAIPEG     GEMINIPEG       HUSDPEG        PAXPEG   STASISPEG
1  2022-06-29 -2.383111e-03  0.00010 -0.0044920717  2.048424e-03 -1.543622e-04  1.639760e-02 -0.04452180
2  2022-06-28 -1.414367e-03  0.00005 -0.0020128418  1.531139e-03 -3.612265e-04  1.710005e-02 -0.03907985

Thanks

  • Hi @mkch, if you can share a minimal reproducible example, [including a small dataset to reproduce your output](https://stackoverflow.com/a/5963610/11856430), that would be great! – Leon Samson Oct 04 '22 at 11:25
  • Already in the post :) –  Oct 04 '22 at 11:32
  • Pasting a sample of the data is different. Please check the link, you can use the `dput` function for example. Besides that, I think the histogram is not needed since the date is not used in that I think? – Leon Samson Oct 04 '22 at 11:36
  • Please stay calm and [check this](https://stackoverflow.com/help/how-to-ask), the section "help other to reproduce the problem", and my previous link. Isolate the problem with a reproducible dataset. You did not provide data. This will help us greatly. I am just trying to help you to improve your question, so that answers can target your problem directly. The answer below from Emmanual Hamel did not work for you because he does not have your dataset. – Leon Samson Oct 04 '22 at 14:34

1 Answers1

2

You can use the plot function only when you want to use dates. It works very well. Here is an example :

date <- seq(from = as.Date("2001-01-01"), to =  as.Date("2020-01-01"), by = "quarter")
returns <- rnorm(n = length(date))
plot(x = date, y = returns, type = "l")
Emmanuel Hamel
  • 1,769
  • 7
  • 19