Итак, я работал над этим R-сценарием последний год, но я его не написал, и мне нужно добавить дополнительную группу в график. До того, как я добавил группу L1 Spanish
, этот сюжет был напечатан красиво [см.
Старый график ]. Но теперь я просто получаю ошибку
"Ошибка в barplot.default (coh, ylim = c (0, 100), ylab = c ("% Source "),
: 'высота' должна быть вектором или матрицей "
Образец данных:
L1 SCond isSource aspectNames
L1 Spanish I 1 Imperfective
L1 Spanish I 1 Imperfective
L1 Spanish P 0 Perfective
L1 Spanish P 0 Perfective
L1 Spanish I 0 Imperfective
L1 Spanish I 0 Imperfective
English P 1 Perfective
English I 1 Imperfective
English I 1 Imperfective
English P 1 Perfective
English P 1 Perfective
English I 1 Imperfective
L2 Spanish P 1 Perfective
L2 Spanish P 0 Perfective
L2 Spanish P 0 Perfective
L2 Spanish I 0 Imperfective
L2 Spanish I 1 Imperfective
L2 Spanish P 1 Perfective
Japanese I 1 Imperfective
Japanese I 1 Imperfective
Japanese P 1 Perfective
Japanese P 1 Perfective
Japanese P 1 Perfective
Japanese P 1 Perfective
Единственные изменения, которые я сделал в следующем коде из оригинала, это добавление L1 Spanish
и text(2.3,-40, "Error bars +/- 1 SE")
dat <- subset(dat, SCRF != "A")
dat$isSource <- ifelse(dat$SCRF=="S", 1, 0)
tapply(dat$isSource, list(dat$SCond, dat$L1), mean)
tapply(dat$isSource, list(dat$SCond), mean)
tapply(dat$isSource, list(dat$L1), mean)
coh <- rbind()
coh.ses <- rbind()
for(g in levels(dat$L1)){
w <- subset(dat, L1==g)
w.subj <- 100*tapply(w$isSource, list(w$SCond, w$ID), mean)
mean.subj <- apply(w.subj, 1, mean, na.rm=TRUE)
# calculate the standard deviation
sd.subj <- apply(w.subj, 1, sd, na.rm=TRUE)
# calculate the lengths (number subjects)
ns.subj <- apply(w.subj, 1, numSubjs)
# calculate the standard errors
ses <- sd.subj/sqrt(ns.subj)
print(mean.subj)
coh <- cbind(coh,mean.subj)
coh.ses <- cbind(coh.ses, ses)
}
par(mar = c(4, 4, 0, 2)+2)
bottom = paste("Language group")
CRnames = c("English", "L1 Spanish","L2 Spanish", "Japanese")
legendText = c("Imperfective", "Perfective")
xs <- barplot(coh, ylim=c(0,100), ylab=c("% Source"), names.arg=CRnames,
cex.names=1.7, cex.lab=2, sub=bottom, font=2,
font.sub=1,cex.sub=1.7,las=1,
legend=F, beside=T)
legend(3.8, 100, text.width=2, legendText, fill=c("gray35", "gray90"), cex=1)
text(2.3,-40, "Error bars +/- 1 SE")
Есть идеи, что происходит ???