다음과 같은 데이터가 있다.
blue=rbind(c(5,3,4,3),
c(3,2,5,1))
dimnames(blue)<-list(c("A","B"),c("t1","t2","t3","t4"))
red=rbind(c(1.7,3.5,1.6,1.1),
c(2.1,1.0,1.7,0.5))
dimnames(red)<-list(c("A","B"),c("t1","t2","t3","t4"))
blue
## t1 t2 t3 t4
## A 5 3 4 3
## B 3 2 5 1
red
## t1 t2 t3 t4
## A 1.7 3.5 1.6 1.1
## B 2.1 1.0 1.7 0.5
이 자료를 가지고 barplot을 그려본다.
par(mfrow=c(1,2))
barplot(blue,col=c("lightblue","blue"),ylim=c(0,10))
barplot(red,col=c("salmon","red"),ylim=c(0,10))
par(mfrow=c(1,1))
여기서 문제이다. 이 두개의 그래프를 겹치게 그려 blue에 비해 red가 튀어나와 보이는 그래프를 그리려면 어떻게 해야 할까?
barplot(blue,col=c("lightblue","blue"),ylim=c(0,10),xlim=c(0,9),
space=c(0,1,1,1),axisnames=FALSE)
barplot(red,col=c("salmon","red"),ylim=c(0,10),axes=FALSE,
space=c(0.5,1,1,1),add=TRUE)