Superscript labels in r googleVis

187 views Asked by At

I coded simple sankey with r googleVis package:

DF= data.frame(From=c('A', 'B', 'C'),
               To=c('D','D', 'F'),
               Weight=c(0.460, 5.100, 2.393),
               Weight.html.tooltip = paste(c(0.460, 5.100, 2.393), paste(expression(m^3))))

plot(gvisSankey(DF,from="From", to="To", weight="Weight",
           options=list(width = "1200",
                        height = "600",
                        sankey="{
                        link: {colorMode: 'gradient', color: { fill: '#green' } },
                        node: {nodePadding: 80, width:50, color: { fill: '#a61d4c'} },
                        tooltip: {isHtml:'true'}
                               }"
                        )))

I am trying to get units in cubic meters, but I am stuck. Usually, superscript text is implemented with expression function in r. But in this case, labels are strings from a data.frame. Is there a way to write strings in superscript text?

1

There are 1 answers

0
JerryTheForester On

After quite some time, here is the solution of my problem. I also formatted digits, since display is more convenient that way.

DF= data.frame(From=c('A', 'B', 'C'),
               To=c('D','D', 'F'),
               Weight=c(0.460, 5.100, 2.393),
               Weight.html.tooltip = paste('<p><nobr>',  format(round(c(0.460, 5.100, 2.393), 2), nsmall = 2), 'm<sup>3</sup></nobr></p>'))

plot(gvisSankey(DF,from="From", to="To", weight="Weight",
                options=list(width = "1200",
                             height = "600",
                             tooltip="{isHtml:'true'}",
                             sankey="{
                             link: {colorMode: 'gradient', color: { fill: '#green' } },
                             node: {nodePadding: 80, width:50, color: { fill: '#a61d4c'} }
                             }"
                        )))