开发者

Split the plot for above and below parts for 3 factorial barploting

I need to barplot the above- and belowground biomass against 3 factors. For each biomass, I am able to plot it using the barchart from lattice, however, I have no idea as to plot two of them, ie, aboveground biomass on the positive, and belowground on the negetive part of the Y axis. Here is the test code for my data, where A, B, C are full factorial factors:

library(lattice)
above <- runif(108)
below <- runif(108)
A <- rep(c("ab", "bc", "cd"), each=36)
B <- rep(1:3, 36)
C <- gl(3, 4, 108, c(30, 60, 90))

barchart(above~A|B+C)
barchart(below~A|B+C)

#This is what I used to do for two factors using barplot
par(mfrow=c(2, 1), mai=c(0, 1, 0.5, 0.5))
agg.abv <- aggregate(above, by=list(A, B), mean)
abv <- matrix(agg.ab开发者_Go百科v[, 3], ncol=nlevels(A), dimnames=list(levels(A), levels(B)))
agg.bel <- aggregate(below, by=list(A, B), mean)
bel <- matrix(agg.bel[, 3], ncol=nlevels(A), dimnames=list(levels(A), levels(B)))
barplot(abv, beside=T, ylim=c(0, 1))
barplot(abv, beside=T, ylim=c(1, 0))

but how about 3 factors?

I am quite new to trellis ploting system, so, any idea is very welcome

All the best

Marco


Here is one way of doing it:

  1. Your "above" and "below" values should be in a single variable
  2. Values "below" should be negative.
  3. Include the origin=0 parameter to barchart

For example:

df <- data.frame(
    x <- runif(108, min=-1, max=1),
    A = rep(c("ab", "bc", "cd"), each=36),
    B = rep(1:3, 36),
    C = gl(3, 4, 108, c(30, 60, 90))
)

barchart(x~A|B+C, data=df, origin=0)

Split the plot for above and below parts for 3 factorial barploting

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜