如何处理条形图中不需要的180度旋转x轴

时间:2014-02-05 04:27:51

标签: r plot

此图注意到行x轴(标有1%等)旋转。

enter image description here

为什么我的代码会在下面发生。我怎样才能恢复正常?

dat <- read.table("http://dpaste.com/1586262/plain/")
colnames(dat) <- c("Method", "Coverage",  "error 0%", "error 1%", "error 2%", "error 4%")

pdf(file="~/Desktop/Temp.pdf",height=7,width=10);

layout(matrix(c(1,2,3,3),nrow=2,byrow = TRUE),heights=c(2,0.2))
par(omi=c(0,0.2,0.1,0.2))
barcols <- c("#636363","#bdbdbd")


lapply(unique(dat$Coverage),
        function(x){
            par(las=2);
            z<-as.matrix(dat[dat$Coverage==x,-(1:2)]);
            colnames(z)=NULL;
            rownames(z)=NULL;
            bp <- barplot(z,beside=TRUE,col=barcols,border=NA,ylim=c(0,1),xlab="Error rate")
            title(main=x,cex.main=1.75,font.main=1)
            xaxislab <- c("0%","1%","2%","4%") 
            axis(1,at=colMeans(bp),xaxislab,lwd=0,lwd.tick=1)
            abline(h=0)
          } 
)         

par(mar=c(0,0,0,0))
plot(NA,xlim=c(0,1),ylim=c(0,1),ann=FALSE,axes=FALSE)
legend("topleft",c("Method1","Method2"),box.col="white",fill=barcols,cex=1.75,horiz=TRUE,border=NA)
dev.off()

1 个答案:

答案 0 :(得分:3)

您目前有par(las=2)表示“始终垂直于轴”,但您可能需要las=1表示“始终水平”。