2016-11-04 56 views
2

我试图用barplot进行绘图,当hist(breaks=200)时,barplot可以以不同的颜色。但是当hist(breaks=1000)不能在barplot中改变颜色。并且为什么ylab在组合三张地块时没有显示在地图上?可以在单个地块中显示)。当组合图块时不能改变barplot的颜色

breaks=200 breaks=1000

这里是我的代码:符= 1000,不能改变颜色。

def.par <- par(no.readonly = TRUE) # save default, for resetting... 
x <- pmin(3, pmax(-3, rnorm(5000))) 
y <- pmin(3, pmax(-3, rnorm(5000))) 
xhist <- hist(x, breaks=1000, plot=FALSE) 
yhist <- hist(y, breaks=1000,plot=FALSE) 
top <- max(c(xhist$density, yhist$density)) 
xrange <- c(-3,3) 
yrange <- c(-3,3) 
nf <- layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), c(3,1), c(1,3), TRUE)#layout.show(nf)ZSSS 

par(mar=c(3,3,0,0)) 
plot(x, y, xlim=xrange, ylim=yrange, xlab="T1", ylab="T2") 

par(mar=c(0,3,1,1)) 
barplot(xhist$density, axes=TRUE, ylim=c(0, top),ylab="T3",col="red") 

par(mar=c(3,0,1,1)) 
barplot(yhist$density, axes=TRUE, xlim=c(0, top),xlab="T4",space=0, horiz=TRUE,col="green") 

par(def.par) 

回答

2

只需更改边框的颜色:

def.par <- par(no.readonly = TRUE) # save default, for resetting... 
x <- pmin(3, pmax(-3, rnorm(5000))) 
y <- pmin(3, pmax(-3, rnorm(5000))) 
xhist <- hist(x, breaks=100, plot=FALSE) 
yhist <- hist(y, breaks=100,plot=FALSE) 
top <- max(c(xhist$density, yhist$density)) 
xrange <- c(-3,3) 
yrange <- c(-3,3) 
nf <- layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), c(3,1), c(1,3),TRUE)#layout.show(nf)ZSSS 

par(mar=c(3,3,0,0)) 
plot(x, y, xlim=xrange, ylim=yrange, xlab="T1", ylab="T2") 

par(mar=c(0,3,1,1)) 
barplot(xhist$density, axes=TRUE, ylim=c(0, top),ylab="T3",col="red", border = "red") 

par(mar=c(3,0,1,1)) 
barplot(yhist$density, axes=TRUE, xlim=c(0, top),xlab="T4",space=0, horiz=TRUE,col="green", border = "green") 
+0

谢谢你,但你知道为什么'ylab'(T2,T3,T4)在三个地块并未出现!? – Ziv