mages / googleVis

Interface between R and the Google Chart Tools
https://mages.github.io/googleVis/
358 stars 156 forks source link

Sankey Chart: sankey.link.color.fillOpacity has no effect? #73

Closed r-archer37 closed 6 years ago

r-archer37 commented 6 years ago

I'm making Sankey charts and with some link colors, I think the chart would look a lot better with links having lower transparency values. However, no matter what value I pass the outcome seems to be no different.

Example code:

s=gvisSankey(df
             ,chartid=chart_id
             ,options = list(
               width="1300px",
               height="1300px",
               sankey="{
                node: {
                  label: {
                    fontName: 'Helvetica'
                    ,italic: false
                    ,bold: false
                    ,fontSize: 12
                  },
                  interactivity: true,
                  labelPadding: 5,
                  nodePadding: 10,
                  width: 20
                },
                link: {
                  color: {fill: '#b2ade6', fillOpacity: .05} //# fillOpacity does nothing?
                }
               }",
               tooltip="{
                isHtml: true
               }"
             )
           )
mages commented 6 years ago

Here is a smaller reproducible example:

library(googleVis)
dat <- data.frame(From=c(rep("A",3), rep("B", 3)), 
                  To=c(rep(c("X", "Y", "Z"),2)), 
                  Weight=c(5,7,6,2,9,4))

plot(gvisSankey(dat, from="From", to="To", weight="Weight",
                options = list(
                  sankey="{link: {color: {fill: '#d799ae', fillOpacity: 0.8}}}")
))

I can't see that googleVis is causing this issue, afaik we are following the Google documentation here. Currently, Google is working on the rollout of a new version of the Google API. Perhaps, this is causing the behaviour. The Google Forum has more info: https://groups.google.com/forum/#!forum/google-visualization-api

r-archer37 commented 6 years ago

Thanks for the pointer! Looking backward from there, it seems there was a change to this in 2015: https://groups.google.com/d/msg/google-visualization-api/eP8bMUyChxw/0BsCDszSUykJ

It should be sankey.link.defaultOpacity

Here's a working revision of your example:

library(googleVis)
dat <- data.frame(From=c(rep("A",3), rep("B", 3)), 
                  To=c(rep(c("X", "Y", "Z"),2)), 
                  Weight=c(5,7,6,2,9,4))

plot(gvisSankey(dat, from="From", to="To", weight="Weight",
                options = list(
                  sankey="{link: {color: {fill: '#d799ae'}, defaultOpacity: 0.2}}")
))
mages commented 6 years ago

Thanks for the follow up.