2017-02-15 14 views
0

我在鹼的圖形,使用R的layout命令在彼此的頂部上堆疊的製作和箱線圖。 圖像看起來很大,但來自不同的地塊即y軸標籤重疊(在紅色圓圈中高亮顯示):R基本圖形:從不同的曲線圖重疊軸刻度標籤與佈局

overlapping axis labels

類似的問題,在網上都在這裏,但沒有人使用layout

我不想擴大地塊之間的空間,我不認爲這會很好看。

如何 我試着減少字體大小,但仍標籤去積區之外。 我怎麼能集R的箱形圖和柱狀圖,刻度標記不走的上方或下方的紅線,即最大/最小y值,上面的圖片嗎?

一些示例代碼

legend_space <- -0.26 
right <- 10.5 
bottom <- 0 
left <- 5 
top <- 0 
cex_main = 1 
setEPS() 
postscript('figure.eps') 
g1 <- c() 
g2 <- c() 
p <- c() 
percent <- c() 
sum_p <- c() 
sum_percent <- c() 
g1_means <- c() 
g2_means <- c() 
xaxis <- c() 
sum_p[1] <- 0.0430904 
xaxis[1] <- 2984116 
p[1] <- 0.0430904 
percent[1] <- -65.1758 
sum_percent[1] <- -65.1758 
g1[1] <- list(c(47.058824,100.000000,100.000000)) 
g1_means[1] <- 84.482759 
g2[1] <- list(c(13.750000,4.123711,96.000000)) 
g2_means[1] <- 19.306931 
sum_p[2] <- 0.0443229 
xaxis[2] <- 2984148 
p[2] <- 0.0587825 
percent[2] <- -73.8956 
sum_percent[2] <- -69.332 
g1[2] <- list(c(94.285714,94.736842,100.000000)) 
g1_means[2] <- 95.145631 
g2[2] <- list(c(10.588235,0.000000,92.592593)) 
g2_means[2] <- 21.250000 
sum_p[3] <- 0.0444647 
xaxis[3] <- 2984157 
p[3] <- 0.124606 
percent[3] <- -40.2577 
sum_percent[3] <- -60.3056 
g1[3] <- list(c(76.315789,94.736842,64.705882)) 
g1_means[3] <- 83.928571 
g2[3] <- list(c(63.529412,0.000000,60.000000)) 
g2_means[3] <- 43.670886 
sum_p[4] <- 0.0393696 
xaxis[4] <- 2984168 
p[4] <- 0.0310268 
percent[4] <- -38.4133 
sum_percent[4] <- -54.7893 
g1[4] <- list(c(59.459459,57.894737,100.000000)) 
g1_means[4] <- 64.864865 
g2[4] <- list(c(35.294118,6.250000,36.363636)) 
g2_means[4] <- 26.451613 
sum_p[5] <- 0.0304293 
xaxis[5] <- 2984175 
p[5] <- 0.0344261 
percent[5] <- -50.5157 
sum_percent[5] <- -54.0582 
g1[5] <- list(c(62.500000,94.736842,100.000000)) 
g1_means[5] <- 85.849057 
g2[5] <- list(c(52.873563,6.250000,26.666667)) 
g2_means[5] <- 35.333333 
layout(matrix(c(0,0,1,1,2,2,3,3,4,4), nrow = 5, byrow = TRUE), heights = c(0.2,1,1,1,1.4)) 
par(mar = c(bottom, left, top, right)) 
boxplot(g1, xaxt = 'n', range = 0, ylab = '%', ylim = c(0,100), col = 'white', cex.lab=1.5, cex.axis=cex_main, cex.main=cex_main, cex.sub=1.5, xlim = c(0.5,length(g1)+0.5)) 
title('title', outer = TRUE, line = -1.5) 
lines(g1_means, col='dark green', lwd = 3) 
par(xpd=TRUE) 
legend('topright',inset = c(legend_space,0), c('Control', 'Weighted Mean'), col = c('black','dark green'), lwd = c(1,3)) 
boxplot(g2, xaxt = 'n', range = 0, main = NULL, ylim = c(0,100), ylab = '%', col = 'gray', cex.lab=1.5, cex.axis=cex_main, cex.main=cex_main, cex.sub=1.5, xlim = c(0.5,length(g2)+0.5)) 
lines(g2_means, col='dark green', lwd = 3) 
par(xpd=TRUE) 
legend('topright',inset = c(legend_space,0),c('Case', 'Weighted Mean'), col = c('black','dark green'), lwd = c(1,3)) 
par(mar = c(bottom, left, top, right))#'mar’ A numerical vector of the form 'c(bottom, left, top, right)’ 
plot(p, xaxt='n', ylab = 'P', type = 'l', lty = 1, lwd = 3, cex.lab=1.5, cex.axis=1, cex.main=cex_main, cex.sub=1.5, , log = 'y', xlim = c(0.5,length(p)+0.5), ylim = c(min(p,sum_p), max(p, sum_p))) 
points(sum_p, xaxt='n', ylab = 'P', type = 'l', col = 'blue', lty = 2, lwd = 3) 
legend('topright', inset=c(legend_space,0), c('CpG P', 'Moving P Mean'), col = c('black','blue'), lwd=c(3,3), lty=c(1,2)) 
par(mar = c(bottom+5, left, top, right))#'mar’ A numerical vector of the form 'c(bottom, left, top, right)’ 
plot(percent, xaxt='n', ylab = '% Diff.', xlab = 'CpG', type = 'l', lty = 1, lwd = 3, cex.lab=1.5, cex.axis=1, cex.main=cex_main, cex.sub=1.5, xlim = c(0.5,length(percent)+0.5), ylim = c(min(percent, sum_percent), max(percent, sum_percent))) 
points(sum_percent, xaxt='n', xlab = 'CpG', type = 'l', col = 'blue', lty = 2, lwd = 3) 
par(xpd=TRUE) 
legend('topright', inset=c(legend_space,0), c('Percent', 'Moving Mean %'), col = c('black','blue'), lwd=c(3,3), lty=c(1,2)) 
axis(1, at=1:length(xaxis), xaxis) 
dev.off() 
+1

你能提供一個可再現的例子嗎? – count

+0

@count我已經在'par'設置添加的代碼的樣本,以產生5-情節佈局堆 – con

+1

嘗試'拉斯= 2'。 – count

回答

0

由於@count,解決的辦法是簡單地在par設置以使用

las=2las=2設置要垂直讀取的標籤。