R - How can i create graphs using an Aggregate data table?

user2337160

I am going to be receiving an Excel Spreadsheet every month that's a summary of a bunch of different groups. I've created a mockup of what I'm going to be getting. mockup of Excel report

What I need to do is create a number of graphs (in R) using this data where (for example) the first graph is a line graph with the months for groups AB, CDE, and F. The second graph would be a bar chart for the same groups but for the quarters, etc. etc.

If this was the raw data, this wouldn't be as much of a challenge; unfortunately I won't (and can't) get the raw data, so have to make do with this.

I have no idea where to even start with this; should I transpose the data so I have Group | Month | Count? Or transpose it so that the Months are the rows and the groups the columns? I'm still learning R so really open to whatever suggestions you have :) Thanks Chris

sconfluentus

This is the kind of stuff that the tidyverse was invented to address.

If it were me, I would start by breaking it into two sets of data

  1. Quarterly Set
  2. Monthly Set

library(tidyverse)
quarterly<-data%>%select(Q1, Q2, Q3, Q4)%>% t
This selects only the columns listened saves them to a file quarterly and makes a column withQ and the alpha numerics int their own columns. From there you can add columns and group as you wish prior to plotting.

monthly<-data%>%select(-Q1, -Q2,-Q3,-Q4, -Total)%>%t
This saves everything BUT the quarterly and Total values into the data frame months also transposing it so you have a column with months a column for each alpha label to allow you to do your summing then plot.

From there you should be able to use a good ggplot2 tutorial to get you going on the graphs. This is really more about thinking about data structure than programming.

It is always a good idea to break things down into conceptual steps

  • what do I have?
  • what do I need to have?
  • what do I have to do to get there?

Then work through it. Subset the relevant data, restructure it and then plot it.

Once you figure out what you will need to do you can build function to apply each month when you get your aggregates to reduce the burden associated with doing everything manually.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I create table using ASCII in a console?

How can I create a copy of an Oracle table without copying the data?

How do i create graphs and images to show on the same panel in R

How can I create a table to hold data from an iteration in MATLAB?

Using jupyter notebook with an R kernel, how can I suppress printing results updating a data.table by reference?

How do i aggregate data from a table to show the sum of products based on the category using each month as key

Can I aggregate time series data between an on and off date using a data table join or the aggregate function?

How can I create a table using factor data

Without splitting my data, how can i create a new categorical variable using function in R

How can I create custom graphs with python to export as an image to latex?

R: How to create a proportion table strictly using the aggregate function?

How do I aggregate data in a R dataframe

How can I list data and create a summary table?

R: Combine two functions to aggregate data using data.table

How can I aggregate this SQL table into another table?

How can I create and insert data into a table with a special name?

How can I create a WPF data grid with an enhanced table header?

How should I create graphs in Excel using VBA?

How can I create Collapsible Column header in Data Table?

Using graphs, how can I show that the logistic function is just an inverse logit function in R?

How can I aggregate groups in data.table and exclude the row itself?

Using data.table in R, how can I supply the entire .SD to j in addition to creating new variables?

How to create an html table with data that can change using JS

How can I aggregate string data in DataStage?

How do I create a data table in code in R

How can I Create a generic procedure for inserting data from a table?

how can I create a new data frame using exact rows from the old data frame in R Studio?

Create table with aggregate data from another table, using SQL

How can i overlap graphs using Python?