1

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!

carlite71
  • 393
  • 1
  • 4
  • 16
  • This question might be construed as off-topic, as requests for materials/tutorials generally are. You'll probably have better results if you pose the specific programming question you're after, with some sample data and desired output. – Ajean Feb 20 '15 at 21:17
  • Study these for ggplot2 and learn dplyr. I assume you can read your data into R. http://hopstat.wordpress.com/2014/10/30/my-commonly-done-ggplot2-graphs/ and http://www.gettinggeneticsdone.com/2015/02/r-ggplot2-graph-catalog.html Has a book I might get and lots of R code for graphs – lawyeR Feb 20 '15 at 22:07
  • Can you add a URL to an example of the kind of plot you want to make, and give some example data that is typical of what you work with? See here for how to do that: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Ben Feb 21 '15 at 03:59

2 Answers2

2

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
Danny M.
  • 281
  • 1
  • 12
2

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

Anthony
  • 192
  • 10