carlite71
carlite71

Reputation: 413

How to create the equivalent to Excel pivot charts in R/ggplot2

I do a lot of pivot charts and I'm frustrated by Excel. Three weeks ago (as of 2/20/2015) I started learning R hoping to get more productive. With the bare basics covered, I installed ggplot2 in my R-Studio. I searched for ggplot2 tutorials but couldn't find any relevant to what I need.

Being brand new to Stack Overflow I cannot post a picture to illustrate, but my data often includes 2 continuous variables and 2 discrete variables that I use as factors. I need to calculate and graph the mean ± sd (error bars) of three replicates for Variable.1 on one axis (as bars) plus the mean for three replicates for Variable.2 on the second axis (as scatterplot).

My questions are:

1) is it possible to do this with R/ggplot2?

2) Where can I find instructions/tutorials/etc that show how to do it?

I'm willing to go and search for the needle myself... if I could only find the haystack!

Thanks!

Upvotes: 1

Views: 6483

Answers (2)

Anthony
Anthony

Reputation: 192

You can do this with the rpivotTable package. Here's an example using the built-in trees dataset, plotting the average volume as a function of tree height:

library(rpivotTable)
rpivotTable(trees, aggregatorName="Average",  vals="Volume", 
  cols="Height", rendererName="Line Chart")

Pivot Chart created from code example

Upvotes: 2

Danny M.
Danny M.

Reputation: 281

You can try something like this.

1: filter

basic_summ = filter(mprices, state %in% c("California", "New York", "Illinois"))

2: set up data frame for by-group processing.

basic_summ = group_by(basic_summ, quality, state)

3: calculate the three summary metrics

basic_summ = summarise(basic_summ, 
                        sum_amount = sum(amount),
                        avg_ppo = mean(ppo),
                        avg_ppo2 = sum(price) / sum(amount))

basic_summ

Upvotes: 2

Related Questions