Skip to content

Question about which kind of plot to use

7 messages · Max, Dylan Beaudette, Deepayan Sarkar +3 more

Max
#
Hi Everyone,

I've got a question about data representation. I have some psychometric 
data with 5 scores for 15 different groups. I've been asked to show 
some kind of mean plots. The data below is the mean and SD for a given 
group, unfortunately my employer doesn't want me posting full datasets. 
:(

 The groups V,W,X,Y,Z are divided into Bottom, (B), Middle (M) and Top 
(T). An example of my data is shown below.

Score 1
Mean				             SD
	B	    M	    T		    B	  M	    T
V	86.9	13.0	88.8		16.9  2.0	10.5
W	16.1	96.1	17.7		2.2	  4.6	1.7
X	50.7	61.1	74.7		4.7	  3.7	7.6
Y	68.5	99.7	37.6		6.0	  8.0	2.3
Z	92.7	22.3	69.4		6.5	  1.2	2.2

What I did before was a standard mean plot:

plotMeans(w$score1, w$Factor, 
error.bars="sd",xlab="Factor",ylab="Score",main="Group W Score 1 Plot")

 However, with 15 groups and 5 scores this turns into 75 individual 
graphs. Is there a way to layer mean plots? Or show several mean plots 
in the Same graph? Any ideas or suggestions would be great.

thanks,

-Max
#
On Wednesday 19 December 2007, Max wrote:
How about a lattice plot using panels ? plot the distribution of each score 
(box and whisker style), using a panel for each group?

a <- rnorm(100)
b <- rnorm(100)
c <- rnorm(100)
 d <- rnorm(100)

library(lattice)
new <- make.groups(a,b,c,d

new$grp <- rep(gl(5,20, labels=c('A','B','C','D','E')), 4)

bwplot(data ~ which | grp, data=new)

Not quite means, but close!

Dylan
#
On 12/19/07, Dylan Beaudette <dylan.beaudette at gmail.com> wrote:
And

demo("intervals", package = "lattice")

shows you how to incorporate confidence intervals.

-Deepayan
#
Deepayan Sarkar wrote:
Perhaps as long as you're learning a new plotting system, you might also 
check out whether ggplot2 might be an option.

I did a quick and dirty version (which I'm sure Hadley can improve and 
also remind me how to get rid of the legend that shows the "3" that I 
set the size to).

Assuming your data is re-shaped, so it comes out something like mine in 
the artificial example below, then it's a two-liner in ggplot:


maxdat.df <- data.frame (
    score1 =  rnorm(9, mean = rep(c(10,20,30), each = 3), sd = 1 ) ,
    SD = runif(9) * 2 + .5,
    Group = factor ( rep ( c("V", "W", "X"), each = 3 ) ),
    subGroup = rep( c("B","M","T"), 3) )
   
maxdat.df

library(ggplot2)
ggp <- ggplot ( maxdat.df, aes (y = score1, x = interaction(Group , 
subGroup), min = score1 - SD, max = score1 + SD, size = 3) )
ggp + geom_pointrange() + coord_flip()


Eric
#
Max wrote:
Hi Max,
This may get a bit crowded, but brkdn.plot (plotrix) will do something 
like this. I think you would want your group variable as the "groups" 
argument (!) and the variable that specifies Bottom/Middle/Top as the 
"obs" argument. Pass "sd" as the "md" argument to get standard deviation 
bars.

Jim
#
Take the size = 3 out of the aesthetic mappings, and put it directly
in geom_pointrange(size = 3) - this way you are setting the size to 3
(mm) rather than asking ggplot to map a variable containing only the
value 3 to the size of the points/lines.  It's a subtle but important
distinction, and I need to figure out how to explain it better.

Hadley
1 day later
Max
#
hadley wickham presented the following explanation :
Thanks everyone for all the help. I'll be playing around with the 
various suggestions I got. :)