r googleVis中的上标标签

时间:2016-12-23 09:55:06

标签: r google-visualization googlevis

我用r googleVis包编写了简单的sankey:

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

我试图以立方米为单位,但我被卡住了。通常,上标文本在r中使用expression函数实现。但在这种情况下,标签是来自data.frame的字符串。有没有办法用上标文本写字符串?

1 个答案:

答案 0 :(得分:0)

经过一段时间,这是我的问题的解决方案。我也格式化了数字,因为显示更方便。

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