rChart nPlot - update yAxis label
Asked Answered
R

1

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,

Ru answered 8/10, 2013 at 5:9 Comment(5)
do you want a dollar sign into the y-axis title?Compressive
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').Mauney
@Compressive I want to add dollar signs to the y axis labels, e.g. something like scale_y_continuous("Price", labels = dollar) from scales packageRu
@Mauney so do I have re-install the rCharts package?Ru
Yes. devtools::install_github('rCharts', 'ramnathv', ref = 'dev')Mauney
M
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} !#")
Mauney answered 9/10, 2013 at 2:9 Comment(7)
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?Ru
try n1$yAxis(tickFormat = "#! function(d) {return '$' + d3.format(',.2f')(d)} !#")Marianamariand
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. @Mauney where can I find a something more detailed about rCharts? The r documentation for rCharts is very limited. ThanksCompressive
@Compressive Documentation is thin currently, and we are working on it.Mauney
ok, thanks again. For now I'll go through all the question tagged rCharts :)Compressive
If you have questions, raise them on the github page for rCharts. We usually resolve things quickly :) But docs are on the way!Mauney
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)} !#")Sachsen

© 2022 - 2024 — McMap. All rights reserved.