[R] Question about which kind of plot to use
Eric
rmailbox at justemail.net
Thu Dec 20 03:14:07 CET 2007
Deepayan Sarkar wrote:
> On 12/19/07, Dylan Beaudette <dylan.beaudette at gmail.com> wrote:
>
>> On Wednesday 19 December 2007, Max wrote:
>>
>>> 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
>>>
>>>
>> 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!
>>
>
> And
>
> demo("intervals", package = "lattice")
>
> shows you how to incorporate confidence intervals.
>
> -Deepayan
>
>
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
More information about the R-help
mailing list