[R] dotchart for matrix data
Ben Bolker
bbolker at gmail.com
Sat Dec 18 16:06:26 CET 2010
David Winsemius <dwinsemius <at> comcast.net> writes:
>
>
> On Dec 18, 2010, at 7:01 AM, e-letter wrote:
>
> > Readers,
> >
> > I am trying to use the function dotchart. The data is:
> >
> >> testdot
> > category values1 values2 values3 values4
> > 1 a 10 27 56 709
> > 2 b 4 46 47 208
> > 3 c 5 17 18 109
> > 4 d 6 50 49 308
> >
> > The following error occurs
> >
> >> dotchart(testdot,groups=testdot[,2])
> > Error in dotchart(testdot, labels = testdot[, 1], groups = testdot[,
> > 2]) :
> > 'x' must be a numeric vector or matrix
> >
> > According to my understanding (clearly wrong!) of the documentation
> > for dotchart (accessed from the manual in section 'graphics'), columns
> > of data can be selected by 'groups' for subsequent plotting.
>
Following up on David's response:
d <- read.table(textConnection("category values1 values2 values3 values4
1 a 10 27 56 709
2 b 4 46 47 208
3 c 5 17 18 109
4 d 6 50 49 308"),
header=TRUE)
## Something like this is probably as close as you can get with
## stock 'dotchart' -- it does *not* (as far as I can tell) put
## different points on the same line, just groups lines
dotchart(as.matrix(d[,-1]),labels=as.character(d[,1]))
dotchart(as.matrix(d[,c("values1","values2")]),labels=as.character(d[,1]))
## reshaping data:
library(reshape)
mdot <- melt(d)
## using the lattice package
library(lattice)
dotplot(value~category,groups=variable,data=mdot)
dotplot(value~variable,groups=category,data=mdot,auto.key=TRUE,
scales=list(y=list(log=10)))
## you could also use ggplot2 ...
More information about the R-help
mailing list