Hi:
There appear to be several options, but it also seems that the amount of
work required to achieve the goal varies among options.
In situations like this, the sos package comes in handy. For example, it
showed me that your vioplot() function was in package vioplot (unmentioned):
library(sos)
findFn('violin plot')
The default output is sent to a created page in your web browser; I got 23
hits. At least seven packages might be relevant to your problem, including
lattice, caroline and perhaps beanplot. In lattice, the operative panel
function is panel.violin, which is meant to be used in conjunction with
bwplot(). The following is a simplified version of the panel.violin()
example using the singers data:
library(lattice)
bwplot(voice.part ~ height, data = singer,
panel = function(...) panel.violin(...))
This is its most basic use; panel.violin() has its own set of customizable
options. From a brief peek at the violin plot in the caroline package, it
appears to take a grouping factor with its by = argument as well.
It may also be advantageous to rearrange your data into a single data frame
in long form; if you're pulling the same variable from multiple data sets or
have the data from each year in separate columns, then it would be
productive to reshape the data (e.g., with package reshape(2)) before
sending it to the graphics function. Lattice may be a convenient way to go,
especially if you want separate panels by year, for example. A data frame
with columns response, year and whatever else you need for grouping should
be enough to get the lattice version running.
I haven't looked at the functions for violin plots in the caroline and
beanplot packages, but you should also look at what they have to offer, as
one or more of them may be suitable for your particular purposes.
HTH,
Dennis
On Thu, Dec 23, 2010 at 5:10 AM, Matthew Vernon
<M.C.Vernon@warwick.ac.uk>wrote:
> 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
>
> ______________________________________________
> R-help@r-project.org 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.
>
[[alternative HTML version deleted]]