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.