我尝试使用以下代码,结果显示在图像中:
如何使上方图形的y轴具有与下方图形相同的形状?
我使用的脚本为:
count<-matrix(ESTRATTORE$VALORI, nrow=5,ncol=3)
lower=c(0,4500)
upper=c(7500,9000)
y_outer=16.5
lowspan=c(0,11)
topspan=c(lowspan[2]+1,16.5)
ylabel="Time (sec)"
cnvrt.coords <-function(x,y=NULL){
xy <- xy.coords(x,y, recycle=TRUE)
cusr <- par('usr')
cplt <- par('plt')
plt <- list()
plt$x <- (xy$x-cusr[1])/(cusr[2]-cusr[1])
plt$y <- (xy$y-cusr[3])/(cusr[4]-cusr[3])
fig <- list()
fig$x <- plt$x*(cplt[2]-cplt[1])+cplt[1]
fig$y <- plt$y*(cplt[4]-cplt[3])+cplt[3]
return( list(fig=fig) )
}
subplot <- function(fun, x, y=NULL){
old.par <- par(no.readonly=TRUE)
on.exit(par(old.par))
xy <- xy.coords(x,y)
xy <- cnvrt.coords(xy)$fig
par(plt=c(xy$x,xy$y), new=TRUE)
fun
tmp.par <- par(no.readonly=TRUE)
return(invisible(tmp.par))
}
plot(c(0,1),c(0,y_outer),type='n',axes=FALSE,ylab=ylabel,xlab='')
subplot(barplot(as.matrix(count),col=terrain.colors(5),ylim=lower,xpd=FALSE,las=1,axis.lty=1,names.arg = c("H", "M", "L")),x=c(0,1),y=lowspan)
subplot(barplot(as.matrix(count),col=terrain.colors(5),ylim=upper,xpd=FALSE,xaxt='n',axes=T,las=2), x=c(0,1),y=topspan)
lowertop=lowspan[2]+0.1 # Where to end the lower axis
breakheight=0.5 # Height of the break
upperbot=lowertop+breakheight # Where to start the upper axes
markerheight=0.4 # Heightdifference for the break markers
markerwidth=.04 # With of the break markers
lines(c(0,0),c(1,lowertop))
lines(c(markerwidth/-2,markerwidth/2),c(lowertop-markerheight/2,lowertop+markerheight/2))
lines(c(0,0),c(upperbot,14))
lines(c(markerwidth/-2,markerwidth/2),c(upperbot-markerheight/2,upperbot+markerheight/2))