GoogleVis中的上标标签 [英] Superscript labels in r googleVis

查看:155
本文介绍了GoogleVis中的上标标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  DF = data.frame(From = c('A', 'B','C'),
To = c('D','D','F'),
重量= c(0.460,5.100,2.393),
重量.html.tooltip = paste(c(0.460,5.100,2.393),paste(表达式(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中的表达式函数实现。但在这种情况下,标签是来自data.frame的字符串。有没有一种方法可以在上标文本中编写字符串?

解决方案

经过一段时间,以下是我的问题的解决方案。

  DF = data.frame(From = c('A')数据格式化数字,因为显示更方便。 ('D','D','F'),
权重= c(0.460,5.100,2.393),
Weight.html.tooltip = paste('< p>< nobr>',格式(round(c(0.460,5.100,2.393),2),nsmall = 2),'m< 3> < / 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'}}
}
)))


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?

解决方案

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

这篇关于GoogleVis中的上标标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆