Christophe Bouffioux
2010-Sep-27 10:54 UTC
[R] bwplot superpose panel.points from another dataframe
Hi everybody, using bwplot for producing panel boxplot with 3 dimensions i want to add a mark on each boxplot representing one individual (on all its dimensions) till now, i didn't succeed getting the desired solution I want as well to keep the median symbols as a line Many thanks for your help christophe here is the tested code: ######################## library(lattice) ex <- data.frame(v1 = log(abs(rt(180, 3)) + 1), v2 = rep(c("2007", "2006", "2005"), 60), z = rep(c("a", "b", "c", "d", "e", "f"), e = 30)) # the individual to be marked ex2 <- data.frame(v1b = log(abs(rt(18, 3)) + 1), v2 = rep(c("2007", "2006", "2005"), 6), z = rep(c("a", "b", "c", "d", "e", "f"), e = 3)) ex3 <- merge(ex, ex2, by=c("v2","z")) bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2), pch = "|", par.settings = list( plot.symbol = list(alpha = 1, col = "transparent",cex = 1,pch = 20)), panel = function(x, y){ panel.bwplot(x, y) X <- tapply(ex3$v1b, ex3[,c(1,2)], max) Y <- seq(length(unique(ex3[,c(1,2)]))) panel.points(X, Y, pch = 17, col = "red") }) [[alternative HTML version deleted]]
Peter Ehlers
2010-Sep-27 16:18 UTC
[R] bwplot superpose panel.points from another dataframe
On 2010-09-27 4:54, Christophe Bouffioux wrote:> bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2), > pch = "|", > par.settings = list( > plot.symbol = list(alpha = 1, col = "transparent",cex = 1,pch = 20)), > panel = function(x, y){ > panel.bwplot(x, y) > X<- tapply(ex3$v1b, ex3[,c(1,2)], max) > Y<- seq(length(unique(ex3[,c(1,2)]))) > panel.points(X, Y, pch = 17, col = "red") > }) >Perhaps this is what you're trying to achieve: bwplot(v2 ~ v1 | z, data = ex3, layout=c(3,2), panel = function(x, y){ panel.bwplot(x, y, pch="|") X <- tapply(ex3$v1b, ex3[, 1:2], max) Y <- seq(nrow(unique(ex3[, 1:2]))) panel.points(X, Y, pch = 17, col = "red") }) (I didn't see any need for your par.settings.) I'm not crazy about the way you define X,Y. I think I would augment the data frame appropriately instead. -Peter Ehlers