noaa-onms / cinms

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

Translate Pelagic CalCOFI interactive figures from plotly to dygraphs #43

Closed mspector13 closed 3 years ago

mspector13 commented 3 years ago

Some issues/critiques of the interactive figures [generally] across the site.

Consensus: the dygraphs are more streamlined than the plotly graphs (e.g. CalCOFI data in "Pelagics").

We should therefore overhaul all of the plotly figures and remake them with dygraphs instead.

One issue with dygraphs: the slider bar at the bottom is good, but the data represented in the slider bar may be misleading. Solution: turn up alpha to 11, or find another workout.

Dygraphs documentation

Dygraphs range selector visual representation

Dygraphs range selector code

mspector13 commented 3 years ago

Update: we're still not fully consistent with our interactive plots @bbest @superjai

Todo:

Screen Shot 2020-11-02 at 11 41 12 AM
bbest commented 3 years ago

Why does CalCOFI Pelagic use plotly, eg:

image

vs Key climate & ocean drivers using dygraphs?:

image

Because of historical association with the Integrated Ecosystem Assessment (IEA) program which shaded the last 5 years and used ggplot, which is easily converted to interactive with plotly::ggplotly(). The other reason I used ggplotly was to optionally render as a static ggplot for use in output report formats as pdf and docx.

OLD Way

NEW Way

Let's try this instead:

bbest commented 3 years ago

Could simply rename the old plotting function calcofi_plot() to calcofi_plotly() and update calcofi_plot() to use dygraphs so you don't have to change all the modal windows that use the existing function. See nms4r function here:

superjai commented 3 years ago

Hey @bbest - I translated the plotly graph into dygraphs. But I have run into 2 issues and I haven't updated the nms4r package yet. Check out the dygraph below. Screen Shot 2020-12-08 at 8 14 02 PM

The first issue is the smaller one and has to do with the shading color. Dygraph plots make it pretty easy to show error bars, but the default coloring has the bars being a lighter shade of the main line's color. I can't figure out how to specify that the error bar color should be something other than that lighter shade. I actually think that the dygraph default makes sense and the colors of the plot should be kept as shown. If the error bar was shaded a variant of blue, it would pretty easily merge with the horizontal line. Also, with the error bar being a lighter shade of the main line, it clearly communicates that the error bar is in some way connected with the main line.

The second issue is that I don't think it makes sense to plot the standard deviation. The data isn't normally distributed and values below zero don't make biological sense for the y axis transformation (since a mean abundance of 0 would yield a y-axis-transformed value of 0).

Any thoughts?

superjai commented 3 years ago

Hey @bbest - let's look at an example of a calcofi plot from the condition report, as follows: Screen Shot 2020-12-08 at 8 58 31 PM

My suggestion would be for me to just copy this format in dygraphs for calcofi plots. That is to plot the mean and standard deviation as horizontal lines, and then to shade in areas of the plot that are above or below one standard deviation. I'll need to do a little bit of thinking to figure out how to shade in just the abnormally high/low areas, but I don't think it will present too much of a challenge.

Should I go ahead with this approach?

bbest commented 3 years ago

Nice work @superjai!

Can you please start with the simplest version suggested above as NEW Way?

The Anchovy figure you produced has the std dev gray ribbon as time-varying, whereas we want a time-invariant (ie straight horizontal line, not varying along time axis) similar to the solid green lines from Condition Report immediately above. If you make the historical mean blue then error bar should be a blueish shade of this. Voila!

superjai commented 3 years ago

Hey @bbest - sorry for the confusion. How is this? Screen Shot 2020-12-09 at 11 24 23 AM

bbest commented 3 years ago

Ok, let's use dygraph's horizontal-shading, eg:

quantmod::getSymbols("MSFT", from = "2014-06-01", auto.assign=TRUE)
## [1] "MSFT"
ret = ROC(MSFT[, 4])
mn  = mean(ret, na.rm = TRUE)
std = sd(ret, na.rm = TRUE)

dygraph(ret, main = "Microsoft Share Price") %>% 
  dySeries("MSFT.Close", label = "MSFT") %>%
  dyShading(from = mn - std, to = mn + std, axis = "y")

image

superjai commented 3 years ago

I think this takes care of it: Screen Shot 2020-12-11 at 12 55 16 PM