5

I am currently using nPlot from rCharts package and how do I add $ signs to the y Axis?

I am thinking I need something like n1$yAxis(labels = ...) but I don't think nPlot supports this?

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

Also, it looks like nPlot is rounding to 5 significant figures (initially thought it was rounding to the nearest 10), is there a way of displaying the full value?

Thanks,

MKa
  • 2,248
  • 16
  • 22
  • do you want a dollar sign into the y-axis title? – Michele Oct 08 '13 at 11:15
  • 1
    I just pushed a fix to the `dev` branch of `rCharts`. It uses 13 digits while converting to json, and can be controlled using `options('rcharts.digits')`. – Ramnath Oct 08 '13 at 14:59
  • @Michele I want to add dollar signs to the y axis labels, e.g. something like scale_y_continuous("Price", labels = dollar) from scales package – MKa Oct 09 '13 at 01:32
  • @Ramnath so do I have re-install the rCharts package? – MKa Oct 09 '13 at 01:38
  • Yes. `devtools::install_github('rCharts', 'ramnathv', ref = 'dev')` – Ramnath Oct 09 '13 at 02:06

1 Answers1

7

I am posting my comment as a full solution so that it is easier for others looking for it.

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
  • 54,439
  • 16
  • 125
  • 152
  • Thanks Ramnath, that added the dollar sign but got rid of ',' the 1,000 separator. How do I add $ and , separator at the same time? – MKa Oct 09 '13 at 02:55
  • 4
    try n1$yAxis(tickFormat = "#! function(d) {return '$' + d3.format(',.2f')(d)} !#") – timelyportfolio Oct 09 '13 at 03:33
  • that is amazing. Never done anything more than running just the examples... through the `yAxis` method you provide named strings (containing JS functions!) to define each part (tick format here) of the `yAxis`. @Ramnath where can I find a something more detailed about rCharts? The r documentation for `rCharts` is very limited. Thanks – Michele Oct 09 '13 at 08:05
  • 4
    @Michele Documentation is thin currently, and we are working on it. – Ramnath Oct 09 '13 at 08:22
  • ok, thanks again. For now I'll go through all the question tagged `rCharts` :) – Michele Oct 09 '13 at 09:16
  • If you have questions, raise them on the github page for rCharts. We usually resolve things quickly :) But docs are on the way! – Ramnath Oct 09 '13 at 12:58
  • 1
    For reference, here's how I managed to do percentages, following the ideas in this post `n1$yAxis(tickFormat = "#! function(d) {return d3.format('.0%')(d)} !#")` – PatrickT May 11 '14 at 18:31