【问题标题】:rChart nPlot - update yAxis labelrChart nPlot - 更新 yAxis 标签
【发布时间】:2013-10-08 05:09:36
【问题描述】:

我目前正在使用 rCharts 包中的 nPlot,如何将 $ 符号添加到 y 轴?

我想我需要像 n1$yAxis(labels = ...) 这样的东西,但我认为 nPlot 不支持这个?

test <- data.frame(object = c("A", "B"), price = c(111333, 876176))
test$Test <- "TEST"
n1 <- nPlot(price~Test, group = "object", data = test, type = "multiBarChart")

另外,看起来 nPlot 正在四舍五入到 5 个有效数字(最初认为它是四舍五入到最接近的 10),有没有办法显示完整值?

谢谢,

【问题讨论】:

  • 你想在 y 轴标题中添加一个美元符号吗?
  • 我刚刚将修复推送到rChartsdev 分支。转json时使用13位,可以使用options('rcharts.digits')控制。
  • @Michele 我想在 y 轴标签上添加美元符号,例如像 scale_y_continuous("Price", labels = Dollar) 来自 scales 包
  • @Ramnath 我要重新安装 rCharts 包吗?
  • 是的。 devtools::install_github('rCharts', 'ramnathv', ref = 'dev')

标签: r rcharts


【解决方案1】:

我将我的评论作为一个完整的解决方案发布,以便其他人更容易寻找它。

require(rCharts) # install the latest from the dev branch
test <- data.frame(object = c("A", "B"), price = c(111333, 876176))
test$Test <- "TEST"
n1 <- nPlot(price~Test, group = "object", data = test, type = "multiBarChart")
n1$yAxis(tickFormat = "#! function(d) {return '$' + d} !#")

【讨论】:

  • 感谢 Ramnath,它添加了美元符号但去掉了 ',' 1,000 分隔符。如何同时添加 $ 和 , 分隔符?
  • 尝试 n1$yAxis(tickFormat = "#!function(d) {return '$' + d3.format(',.2f')(d)} !#")
  • 这太棒了。除了运行示例之外,从来没有做过任何事情......通过yAxis 方法,您提供命名字符串(包含JS 函数!)来定义yAxis 的每个部分(此处勾选格式)。 @Ramnath 我在哪里可以找到有关 rCharts 的更详细信息? rCharts 的 r 文档非常有限。谢谢
  • @Michele 文档目前很薄,我们正在努力。
  • 作为参考,这是我按照这篇文章n1$yAxis(tickFormat = "#! function(d) {return d3.format('.0%')(d)} !#")中的想法设法做百分比的方法@
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 2022-10-17
相关资源
最近更新 更多