2013-10-15 36 views
4

這是一個柱狀圖我R中做了全方位的變量,請在這裏看到: enter image description here如何設置XLIM在HIST()圖同時顯示在一個直方圖

這裏是我以前的代碼得到它:

par(mfrow = c(3, 1)) 
hist(outcome[, 11], main = "Heart Attack", xlim = c(10,20), xlab = "30-day Death Rate") 
hist(outcome[, 17], main = "Heart failure", xlim = c(10, 20), xlab = "30-day Death Rate") 
hist(outcome[, 23], main = "Pneumonia", xlim = c(10,20), xlab = "30-day Death Rate") 

所以,我怎麼能修改我的代碼,以獲得下圖,請看這裏: enter image description here

我需要顯示直方圖的全方位的數據,同時具有一個有限的x- 10-20軸只有15中間

回答

6

沿着這個東西線未經測試的代碼:

par(mfrow = c(3, 1)) 
xrange <- range(c(outcome[, 11],outcome[, 17],outcome[, 23])) 
hist(outcome[, 11], main = "Heart Attack", xlim = xrange,xaxt="n", 
     xlab = "30-day Death Rate") 
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10)) 
hist(outcome[, 17], main = "Heart failure", xlim = xrange,xaxt="n", 
     xlab = "30-day Death Rate") 
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10)) 
hist(outcome[, 23], main = "Pneumonia", xlim = xrange, xaxt="n", 
     xlab = "30-day Death Rate") 
axis(1, at=seq(10,30,by=10), labels=seq(10,30,by=10)) 
+0

謝謝迪文,它工作得很好! –

3

看一看?axis(和?parxaxt參數),例如:

set.seed(1) 
x <- rnorm(100) 
## using xaxt="n" to avoid showing the x-axis 
hist(x, xlim=c(-4, 4), xaxt="n") 
## draw the x-axis with user-defined tick-marks 
axis(side=1, at=c(-4, 0, 4)) 

enter image description here

相關問題