njfrazie
njfrazie

Reputation: 91

R Programming: How to show data labels in rCharts?

I have a bar chart where I want to show the value of the bar above each bar. However, using showValues results in the plot not working. Any ideas?

data2plot <-data.frame(Status=c("Open","Closed","Blocked"),Count=c(200,300,400))     

a <- nPlot(Count ~ Status, data = data2plot, type = "multiBarChart")
a$chart(showValues=TRUE)
a

I'm using nplot, the nvd3 version. I'm open to changing to something else if I need to.

Upvotes: 0

Views: 431

Answers (1)

NicE
NicE

Reputation: 21443

You can change type to discreteBarChart. To format the values displayed, you can use valueFormat, which takes a Javascript function and applies it to the values. Here is some info on d3.format function.

library(rCharts)
a <- nPlot(Count ~ Status, data = data2plot, type = "discreteBarChart")
a$chart(showValues=TRUE)
a$chart(valueFormat="#!d3.format('d')!#")
a

enter image description here

Upvotes: 3

Related Questions