plotmath - R: How do I put two box plots next to each other, keeping same y-range for both? -
let's have 2 data sets, 1 y-range [min0:max0] , other y-range [min1:max1]. how can put both box plots in 1 plot next each other sane y-range [min(min0, min1):max(max0, max1)]?
here's tried:
d0 <- matrix(rnorm(15), ncol=3) d1 <- matrix(rnorm(15), ncol=3)  par(mfrow = c(1, 2)) boxplot(d0) usr <- par("usr") plot.new() par(usr = usr) boxplot(d1, add = true) but keep first plots y-range , squeeze both plots whereas i'd them square.
any ideas?
d0 <- matrix(rnorm(15), ncol=3) d1 <- matrix(rnorm(15), ncol=3)  # using base r graphics lmts <- range(d0,d1)  par(mfrow = c(1, 2)) boxplot(d0,ylim=lmts) boxplot(d1,ylim=lmts) 
you may want think way using grid graphics, either lattice or ggplot2 packages.
here's 1 attempt in ggplot2:
# using ggplot2 library(ggplot2) d <- data.frame(d.type=c(rep(0,15),rep(1,15)),sub.type=rep(c('a','b','c'),10),val=rnorm(30))  p <- ggplot(d, aes(factor(sub.type), val))  p + geom_boxplot() + facet_grid(. ~ d.type) 
and in lattice:
# using lattice library(lattice) bwplot(~ val|sub.type+d.type ,d) 
note how grid-based solutions keep ever having specify limits; specify structure , software rest.
Comments
Post a Comment