Marius Hofert
2011-Mar-26 08:34 UTC
[R] bwplot [lattice]: how to get different y-axis scales for each row?
Dear expeRts, How can I get ... (1) different y-axis scales for each row (2) while having the same y-axis scales for different columns? I coulnd't manage to do this with relation="free" [which gives (1) but not (2)]. I also tried relation="sliced", but it did not give the same y-axis scales within each row (see the fourth row). Further, it "separates" the panels. Cheers, Marius ## minimal example: library(lattice) ## build example data set dim <- c(100, 6, 2, 3) # n, groups, methods, attributes dimnames <- list(n=paste("n=", seq_len(100), sep=""), groups=paste("group=", seq_len(6), sep=""), methods=paste("method=", seq_len(2), sep=""), attr=paste("attribute=", seq_len(3), sep="")) set.seed(1) data <- rexp(prod(dim)) arr <- array(data=data, dim=dim, dimnames=dimnames) arr[,2,,] <- arr[,2,,]*10 arr[,4,2,2] <- arr[,4,2,2]*10 z <- abs(sweep(arr, 3, 1)) df <- as.data.frame.table(z, responseName="error") ## box plot bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(alternating=c(1,1), tck=c(1,0))) ## with relation="sliced" bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(alternating=c(1,1), tck=c(1,0), relation="sliced"))
Marius Hofert
2011-Mar-27 15:20 UTC
[R] bwplot [lattice]: how to get different y-axis scales for each row?
Dear expeRts, I partially managed to obtain what I wanted by using latticeExtra. However, the following questions remain: 1) why do not all x-axis labels appear? [compare bw and bw2] 2) Can I have the y-axis labels on the right margin/side of the plot? Changing the "alternating" argument does not do the job since relation="free" Cheers, Marius library(lattice) library(latticeExtra) ## build example data set dim <- c(100, 6, 4, 3) # n, groups, methods, attributes dimnames <- list(n=paste("n=", seq_len(100), sep=""), groups=paste("group=", seq_len(6), sep=""), methods=paste("method=", seq_len(4), sep=""), attr=paste("attribute=", seq_len(3), sep="")) set.seed(1) data <- rexp(prod(dim)) arr <- array(data=data, dim=dim, dimnames=dimnames) arr[,2,,] <- arr[,2,,]*10 arr[,4,2,2] <- arr[,4,2,2]*10 z <- abs(sweep(arr, 3, 1)) df <- as.data.frame.table(z, responseName="error") ## box plot bw <- bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(y=list(alternating=c(1,1), tck=c(1,0)), relation="free")) (bw2 <- useOuterStrips(combineLimits(bw, extend=FALSE)))) On 2011-03-26, at 09:34 , Marius Hofert wrote:> Dear expeRts, > > How can I get ... > (1) different y-axis scales for each row > (2) while having the same y-axis scales for different columns? > > I coulnd't manage to do this with relation="free" [which gives (1) but not (2)]. > I also tried relation="sliced", but it did not give the same y-axis scales > within each row (see the fourth row). Further, it "separates" the panels. > > Cheers, > > Marius > > ## minimal example: > > library(lattice) > > ## build example data set > dim <- c(100, 6, 2, 3) # n, groups, methods, attributes > dimnames <- list(n=paste("n=", seq_len(100), sep=""), > groups=paste("group=", seq_len(6), sep=""), > methods=paste("method=", seq_len(2), sep=""), > attr=paste("attribute=", seq_len(3), sep="")) > set.seed(1) > data <- rexp(prod(dim)) > arr <- array(data=data, dim=dim, dimnames=dimnames) > arr[,2,,] <- arr[,2,,]*10 > arr[,4,2,2] <- arr[,4,2,2]*10 > z <- abs(sweep(arr, 3, 1)) > df <- as.data.frame.table(z, responseName="error") > > ## box plot > bwplot(error ~ methods | attr * groups, data=df, > as.table=TRUE, notch=TRUE, > scales=list(alternating=c(1,1), tck=c(1,0))) > > ## with relation="sliced" > bwplot(error ~ methods | attr * groups, data=df, > as.table=TRUE, notch=TRUE, > scales=list(alternating=c(1,1), tck=c(1,0), relation="sliced")) >