Creating MultiBarChart with rCharts in Shiny

Hello everyone! I hope someone can help me with this little issue I am having. I have done some research and found that if you use rCharts you can create a bar chart that a client can toggle between viewing the bars as either "stacked" or "grouped". I have seen this called a "MultiBarChart"
If you need clarity, on this website it is shown and entitled "NVD3"

In the example on that website they use the HairEyeColor data frame which seems very well formatted for this process. I have data (a reproducible example is below) where I would like to have date on the x axis of a bar chart, and use the "Weights" and "Running" variables as the bars. In this example I could see how many minutes of exercise occurred for each Running and Weights categories, but also I could stack the bars and see what the total amount of exercise is for that day. Thank you very much for your help! Below is the data frame.

'''
Date <- seq(from = as.Date("2017-01-01"), to = as.Date("2017-01-03"), by = 'day')
Weights <- c(37,42,NA)
Running <- c(60, NA, 90)
df <- data.frame(Dates, Weights, Running)

'''

Hi @zmcclean, you can do it by setting up the data a bit differently.

library(rCharts)

df <- data.frame(Date = as.character(seq(from = as.Date("2017-01-01"), to = as.Date("2017-01-03"), by = 'day')),
                 Time = c(37, 42, NA, 60, NA, 90),
                 Type = c(rep("Weights",3), rep("Running", 3)))

nPlot(Time ~ Date, group = "Type", data = df, type = "multiBarChart")
1 Like

@ginberg Thank you very much for assisting with this problem!
I am a little bit unfamiliar with this process you have described. Are you able to provide some insight into how you complete this process if the variables have hundreds of observations rather than just the 3 I used in this example?
In reality I have approx 50 variables and hundreds of observations in this dataset that is collected from a csv.

@zmcclean I am glad this works for you. I have looked at the example on the rCharts website for the MultiBarChart and it's data format. It has only one numeric variable while your example had two, so I updated it.

In general, if you want to transform your data from one format to the other, the dplyr package is very handy since it has many methods for data manipulation.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.