Superscript labels in r googleVis

拟墨画扇 提交于 2019-12-13 06:41:05

问题


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:


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'} }
                             }"
                        )))


来源:https://stackoverflow.com/questions/41299086/superscript-labels-in-r-googlevis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!