Reputation: 3774
I would like to make the following figure, but am not sure it is possible to mix rows and columns like this.
The example dataframe would be:
trt rain evap drain runoff balance
cc 10 3 2 1 4
ccw 10 2 2 3 3
cs 10 4 1 2 3
sc 10 3 3 3 1
Rain is the input; evap, drain, and runoff the outputs, and balance the difference between the input and output.
Upvotes: 0
Views: 42
Reputation: 764
trt <- c("cc", "ccw", "cs", "sc")
rain <- c(10,10,10,10)
evap <- c(3,2,4,3)
drain <- c(2,2,1,3)
runoff <- c(1,3,2,3)
balance <- c(4,3,3,1)
dat <- data.frame(trt,rain,evap, drain , runoff ,balance)
bp <- barplot(t(as.matrix(dat[,c(3,4,5)] )), col=c("blue","red", "yellow"), cex.axis=1, cex.names=1,names.arg=trt, xlab="Treatment", ylab="Amount", xlim=c(-2, 10), yaxt="n", ylim=c(0,20))
par(new=TRUE)
rect(-1,0,-2,15,col='lightblue')
par(new=TRUE)
for(i in 1:length(balance)){
rect(4.2+i,0,5+i,balance[i],col='green')
axis(1,at=(4.5+i), trt[i],tick=F )
}
text(7, 6, "Balance")
text(-1, 17, "Input\n(same for all)")
text(3, 10, "Outputs")
Upvotes: 1