noaa-onms / cinms

Channel Islands National Marine Sanctuary
https://noaa-onms.github.io/cinms
MIT License
3 stars 1 forks source link

fix decimal (year.#) values of dygraphs to dates (year month) #66

Closed bbest closed 3 years ago

bbest commented 3 years ago

fix decimal (year.#) values of dygraphs to dates (year month)

superjai commented 3 years ago

Hey @bbest & @mspector13 - I have sorted out why the decimalization of the x axis occurs in the following plots: Screen Shot 2020-11-11 at 4 30 03 PM

The final tibble in the function nms4r::plot_intertidal_nms() used to create the plot looks like this: Screen Shot 2020-11-11 at 4 31 50 PM

The x-axis is defined by the column "yr", which provides just a four digit year. So the x axis is not recognized as a date, just as a number which is why the decimalization occurs. In order to convert this to a date (to prevent the decimalization), it would be best to provide the month and day of sampling for every row of data. That data is included in the original data file: Screen Shot 2020-11-11 at 4 39 30 PM

So, the final tibble used for plotting needs to be modified to include this day-month info. I will take care of it.

superjai commented 3 years ago

Hey @bbest & @mspector13 - I have run into an issue with converting the x axis of the plot to dates. My gut reaction is that it can't really be done, given the dataset, and that the plot should stay as it is. But, I could easily be wrong.

So, let's go with an example. Here is the plot from mussels.rmd Screen Shot 2020-11-12 at 8 37 05 PM

Let's examine some of the underlying data (Anacapa from 2003-2005). V in the column header stands for percent cover Screen Shot 2020-11-12 at 8 38 08 PM

The original plot shows percent cover averaged by year. You can see in the table above that, in any given year, the data really bounces around a lot. Additionally, data isn't collected for most months of the year. So, though it would be possible to just plot the raw time series data, I don't think that would add value. Because of the irregularity of sampling, binning by month or quarter doesn't seem to be much of an advantage either. I could set an arbitrary day of the year for the annual average (january 1?), but that doesn't make sense to me either. So, I think that it makes sense to leave the plot itself alone.

Another option would be to change the dygraph options to eliminate the decimalization of the x axis when you zoom in. However, when you zoom in, you see that the x axis numbers just repeat - which seems less than ideal. See image below: Screen Shot 2020-11-12 at 9 35 02 PM

So, I think any change I would make would make matters worse. I could be wrong though - let me know what change you want to see.

bbest commented 3 years ago

Let's update the yr column from numeric to date, say YYYY-06-31 or whatever's the mid day of the year, so the x-axis label is more like a date

superjai commented 3 years ago

Hey @bbest & @mspector13 - check it out: the date issue is fixed Screen Shot 2020-11-23 at 9 56 33 PM