0

Here's a minimal example of my data and the plot I was able to adapt from this tutorial:

require(lattice)

t <- c(0.88,3.52,7.04,10.56,18.48,29.92,29.6,52.8,70.4)

n <- 1000
mu.A <- c(0.4014165,0.2444396,0.2200015,0.1829841,0.2087899,0.1385284,0.2150571,0.2272082,0.1643309    )
mu.C <- c(0.4670488,0.3561108,0.1957407,0.1564677,0.1199911,0.1883665,0.1678103,0.1194251,0.1274065    )

C <- A <- numeric(0)

for (i in 1:length(mu.C)) {C <- c(C,rnorm(mu.C[i],sd=0.031))}
for (i in 1:length(mu.A)) {A <- c(A,rnorm(mu.C[i],sd=0.021))}

data.f <- data.frame(C,A,rep(t,each=n))

colnames(data.f) <- c("C","A","Time")

bwplot(C + A ~ factor(Time),
       data=data.f, 
       xlab="Time",
       ylab="P. Estimate",
       outer=T, # This parameter makes sure that the right hand side variable gets an own panel
       as.table=T,
       panel = function(...,box.ratio) {
         panel.violin(...,col="lightblue",
                      box.ratio=box.ratio)
         panel.bwplot(...,box.ratio=.1,pch="|")
       },
       par.settings = list(box.rectangle=list(col="black"),
                           plot.symbol=list(pch=".",cex=.001),
                           strip=strip.custom(factor.levels=c("C","A"))
       )
)

Here's my problem: This plot doesn't have a proper time axis. It treats each element of t as a category of its own and not as a point on a continuous scale. In the experiment, time was measured and t are mean response time over all participants.

My approach here was to use xyplot() and use panel.violin as the panel function. However, this is not working. In the output, the violins are oriented horizontally and really huge. R also takes a very long time to draw the plot and eventually I have to kill the R-Studio session:

xyplot(C + A ~ Time,
       data=data.f, 
       xlab="Time",
       ylab="P. Estimate",
       panel = function(...) {
         panel.violin(...,col="lightblue")
       },
       par.settings = list(box.rectangle=list(col="black"),
                           plot.symbol=list(pch=".",cex=.001),
                           strip=strip.custom(factor.levels=c("C","A"))
       )
)

I'm not so much looking for someone who just solves the problem for me but rather tells me where I'm making the mistake.

Disclaimer: This is not my real data. It's just a more convenient way to reproduce the data without having to upload it somewhere.

Gerome Bochmann
  • 496
  • 6
  • 19
  • reproducible example please (e.g. give us an example of your second paragraph)? – Ben Bolker Nov 18 '13 at 15:01
  • and you've already seen http://procomun.wordpress.com/2011/04/02/violin-plot/ ? – Ben Bolker Nov 18 '13 at 15:12
  • I will provide the example later today. I was a bit short on time and I still am. Anyway, the link you're providing is exactly what I already know how to do. The problem is that I'm trying to plot measurements which were taken with varying time intervals between them. So, a was measured at `t=0.72s`, b at `t=3.5s` and c at `t=10s`. If I use the example in the link above these will all be plotted with a consistent interval between them. To me this seems due to the fact that the violin plots are superposed on a bwplot. I'm not the expert though. – Gerome Bochmann Nov 19 '13 at 10:52
  • @BenBolker Alright, it took me a long time, but I've edited the question so that it should be less vague and reproducible now. Please let me know if there are any other issues. – Gerome Bochmann Dec 02 '13 at 16:02

0 Answers0