[R] plot separate groups with plotmeans()
Bart Toonen
bart.toonen at gmail.com
Wed Oct 10 17:36:47 CEST 2012
Hi,
This answer may be a bit overdue, but I had a similar problem and it took
me quite some time to find a good solution. When searching with google,
your post kept showing up, so I post this to help others.
The command that worked for me was interaction.plot.
Example:
x <- data.frame(Score=rnorm(100), Time=rep(1:5,
20),Group=factor(rep(c("A","B"),50)))
interaction.plot(x$Group,x$Time,x$Score)
Note, I used 5 Time groups; with 10 groups, no lines showed up.
Bart.
Op woensdag 9 november 2011 01:19:54 UTC+1 schreef Jon Zadra het volgende:
>
> Hi,
>
> I often use plotmeans() from the gplots package to quickly visualize a
> pattern of change. I would like to be able to plot separate lines for
> different groups, but the function gives an error when a grouping
> variable is included in the formula argument.
>
> For instance,
> > require(gplots)
> > x <- data.frame(Score=rnorm(100), Time=rep(1:10, 10),
> Group=factor(rep(c("A","B"),50)))
> > plotmeans(Score ~ Time, x) #works fine
> > plotmeans(Score ~ Time * Group, x)
> Error in .subset2(x, i, exact = exact) :
> attempt to select more than one element
> > plotmeans(Score ~ Time | Group, x)
> Error in ns - 1 : non-numeric argument to binary operator
> In addition: Warning message:
> In Ops.factor(Time, Group) : | not meaningful for factors
>
> The help for plotmeans() states that it accepts a formula object
> including a grouping variable. There is no other grouping argument
> listed. Any help is appreciated, including pointing to a more robust
> function for plotting means.
>
> Thanks,
>
> Jon
> --
> Jon Zadra
> Department of Psychology
> University of Virginia
> P.O. Box 400400
> Charlottesville VA 22904
> (434) 982-4744
> email: za... at virginia.edu <javascript:>
> <http://www.google.com/calendar/embed?src=jzadra%40gmail.com>
> ______________________________________________
> R-h... at r-project.org <javascript:> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list