[R] Vioplot / list help
Matthew Vernon
M.C.Vernon at warwick.ac.uk
Thu Dec 23 14:10:04 CET 2010
Hi,
I have some data (lots of year,distance pairs), which I can
straightforwardly boxplot:
dists <- read.table("movedists.dat")
with(dists,plot(as.factor(V1),V2))
If I want to plot these data as violin plots using vioplot, this
approach doesn't work:
> with(dists,vioplot(as.factor(V1),V2))
Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, :
min not meaningful for factors
I tried making columns by year:
ys=with(dists,by(V2,V1,function(x) x))
or even making that into a matrix:
ysm<-as.matrix(ys,ncols=11)
But still vioplot isn't happy.
After a bit of faff, I end up with:
with(dists,vioplot(dists[V1==1999,2],dists[V1==2000,2],dists[V1==2001,2],
dists[V1==2002,2],dists[V1==2003,2],dists[V1==2004,2],dists[V1==2005,2],
dists[V1==2006,2],dists[V1==2007,2],dists[V1==2008,2],dists[V1==2009,2],
names=1999:2009))
...but this is clearly awful. Surely there's a better way of achieving
this?
Thanks,
Matthew
--
Matthew Vernon, Research Fellow
Ecology and Epidemiology Group,
University of Warwick
http://blogs.warwick.ac.uk/mcvernon
More information about the R-help
mailing list