Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

Data Table Manipulation in R so that variables can be easily charted

I am trying to create a "MultiBarChart" from the rCharts package. I have a large data table with approx 50 variables and hundreds of observations. The example data frame used in the "MultiBarChart" documentation is the HairEyeColor df. This df has a unique characteristic where the df columns are under an overarching heading. In the "MultiBarChart" example, this overarching heading is used to easily chart the values.

In my data table I would like to put only two variables under an overarching heading so that I can do something similar to what is done with the HairEyeColor df.

As an example, imagine I have the variables: "Date", "Name", "Weights", "Running", "Breakfast". I would like to put "Weights" and "Running" under the overarching heading of "Exercise" so that I can create a MultiBarChart with "Date" on the X and "Exercise" on the Y (Exercise should visually be broken into 2 bars: 1 bar for weights, one bar for running). Then I could also filter by "Name". However, in this example I would like to leave "Breakfast" as a singular variable.

I really hope I have explained this well and presented my question in an appropriate manner. I am fairly new to R so help with little things like this is so much appreciated!

below is a sample reproducible 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)
Breakfast <- c(toast, banana, yogurt)
df <- data.frame(Dates, Weights, Running, Breakfast)

'''

I would like to have a way to put the data variables with many observations into a chart like with the input:

'''

nPlot(y ~ Date, group = "Exercise", data = df, type = "multiBarChart")

'''

Sorry this is unorganized... It is a difficult concept for me to wrap my head around. At the end of the day, I have a large data table and would like to present a barchart with the "weights" and "running" data for each date presented.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...