rstudio / dygraphs

R interface to dygraphs
http://rstudio.github.io/dygraphs
Other
365 stars 193 forks source link

Axis reversed with dyStackedBarGroup() #180

Closed odelaigue closed 7 years ago

odelaigue commented 7 years ago

Maybe I am wrong, but I think there is a problem with the the function dyStackedBarGroup() (very useful, thank's!).

If the y-axis is reverses it is ok if there are only bars on the plot :

dygraph(lungDeaths) %>% dyStackedBarGroup(name = c("ldeaths", "mdeaths"))

If the plot mix line en bars, it is also ok :

dygraph(lungDeaths) %>% dyStackedBarGroup(c("ldeaths", "mdeaths")) %>% dyAxis(name = "y", valueRange = c(7000, 0))

But if the plot mix line en bars and the y-axis is reversed only for the bars, the coloring of the bars is upside down :

dygraph(lungDeaths) %>% dyStackedBarGroup(c("ldeaths", "mdeaths"), axis = "y2") %>% dyAxis(name = "y2", valueRange = c(7000, 0))

This type of graphic is very used in hydrology in order to draw hydrographs (with flows and precipitations [liquid + solid] on the same plot).

PS: it is ok with dyStackedRibbonGroup()

odelaigue commented 7 years ago

the dataset :

lungDeaths <- cbind(mdeaths, fdeaths, ldeaths)

jjallaire commented 7 years ago

@klaukh Could you take a look a this?

odelaigue commented 7 years ago

I forgot to say it is the same with dyBarSeries() (and it is OK with the bar chart JS code from http://dygraphs.com used with dyOptions(plotter))

klaukh commented 7 years ago

Yup... looking into this

klaukh commented 7 years ago

I have a bead on the issue, should be able to push a fix by mid next week... just need to get some other things off my plate between now and then. Issue is: I used the bar chart plotter template from the main dygraphs JS site (and the example plotters in the previous R package versions) as the template to do the dyBarSeries, dyMultiColumnGroup and dyStackedBarGroup plotters. The original bar chart plotter (and also the original multi-column plotter) took over the whole chart and never needed to consider the presence of other series, either on the same axis or the y2 axis. When doing the newer, derived plotters I never considered the need to have a second, reversed axis, so the current versions of the plotters also plot the bars from the data point to the 0 point of the first axis... not an issue if you have one axis or if both axes are the same direction and terminate at 0, but certainly an issue if you have a second axis. The dyStackedRibbonGroup was extracted and derived from the code in the undelying dygraph package as opposed to the bar plotters, so that's why it never had this problem. I quick-tested a modified dyBarSeries this morning and got the desired behavior... like I said I just need to get a couple other things off my plate and I should be able to push the fixes by mid next week.

jjallaire commented 7 years ago

Okay, sounds good. Thanks again!

klaukh commented 7 years ago

Alright, so with just a few lines of fixing I was able to produce the following: rplot3 rplot1 rplot2

@odelaigue ... these what you're looking for?

PR #181 has the associated file corrections. Nothing too serious there. Life got in the way so it took a week longer than I had hoped... but I finally got to it! If @odelaigue confirms this is what was desired, then we should be good-go-to.

odelaigue commented 7 years ago

Thank you very much @klaukh, this is exactly what I expected! Very useful to draw hydrographs!