0

I am trying to plot out data along a continuous date axis. I cannot figure out how to create a custom axis to suit my needs. the default plot() function adds dates (2018, 2019, and 2020) on the x axis, but I would like it broken down by year and month, so in plot I have added axes=F.

My data is originally a character string in the format YYYY-mm-dd hh:mm:ss. I've as.Date it before attempting to graph using the plot() function.

plot(df$y ~ df$x, type = "n", xlab = "", ylab = "", axes=F) 
box()
axis(2, at=seq(0,200,30))
axis(1, df2$x, format(df2$x, "%Y-%m"), "month"), seq(1,11000,(11000/24)))

This last line is where I am stuck. I have formatted it over to the format I would like, and it plots, but it plots all 11000~ x axis instances and leaves a thick black bar because there are so many ticks so close together. My data starts at 2018-01, and ends at 2019-11, how can I change this to only have 24 ticks? I think my issue lies in the fact that I do not know how to properly refer to these data values in the sequence section of the axis function.

morgan121
  • 2,213
  • 1
  • 15
  • 33
Kyle
  • 13
  • 2
  • use `at=seq(1,11000,(11000/24))` instead and see if it works. Look at the arguments positions for the `axis()` function. `at` comes at number 2. – Sathish Dec 17 '19 at 00:58
  • [Possible duplicate](https://stackoverflow.com/q/13670062/6478701) – RoB Dec 17 '19 at 08:37
  • I've tried this before Sathish, thank you though. and RoB thank you as well, but I had seem that post as well. The issue I think may be, if I at=sequence the points down to 24, I do not know how to refer to the 24 points I want plotted. Would I have to manually create a vector of these 24 dates? – Kyle Dec 17 '19 at 16:51
  • @Kyle Plot with a subset of the original data, if you want to remove certain data points on the time axis. I assume you know how to subset a data frame, if not try searching it and also look at the man page of `?Extract` – Sathish Dec 17 '19 at 17:24
  • @Kyle If you need proper support, please add sample data, code, output and the expected output. Use `dput()` to add data. – Sathish Dec 17 '19 at 17:28

0 Answers0