2013-07-23 74 views
0

我將三張圖發送到同一頁上的pdf文件。 x軸標籤儘管在我的代碼中具有相同的y座標,但它們的高度不同。我如何解決它?對角標籤佈局

下面是一個例子:

pdf("data_output.pdf", height = 8.5, width = 14) 
graph.frame <- cbind(c(1,2,3,4),c(5,6,7,8),c(9,10,2,2)) 
par(mfrow = c(1,3), mar = c(7.6, 4.1, 6.1, 2.1)) 
colnames(graph.frame) <- c("OneOneOne", "TwoTwoTwo", "ThreeThreeThree") 
labels <- colnames(graph.frame) 
temp1 <- barplot(graph.frame[1,], ylab = "AAA", col = terrain.colors(3), xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
temp1 <- barplot(graph.frame[2,], main = "Title", ylab = "BBB", 
       col = terrain.colors(3), xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
temp1 <- barplot(graph.frame[3,], ylab = "CCC", col = terrain.colors(3), 
       xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
dev.off() 

回答

1

可以設置與ylim軸限制:

?par 
barplot(graph.frame[1,], ylab = "AAA", col = terrain.colors(3), 
     ylim="c(0,10), xaxt = "n") 

pdf("data_output.pdf", height = 8.5, width = 14) 
graph.frame <- cbind(c(1,2,3,4),c(5,6,7,8),c(9,10,2,2)) 
par(mfrow = c(1,3), mar = c(7.6, 4.1, 6.1, 2.1)) 
colnames(graph.frame) <- c("OneOneOne", "TwoTwoTwo", "ThreeThreeThree") 
labels <- colnames(graph.frame) 
temp1 <- barplot(graph.frame[1,], ylim=c(0,10),ylab = "AAA", col = terrain.colors(3), xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
temp1 <- barplot(graph.frame[2,], ylim=c(0,10),main = "Title", ylab = "BBB", 
       col = terrain.colors(3), xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
temp1 <- barplot(graph.frame[3,],ylim=c(0,10),ylab = "CCC", col = terrain.colors(3), 
       xaxt = "n") 
temp2 <- temp1[1:length(labels)] 
text(temp2, par("usr")[3] - 0.35, srt = 45, adj = 1, 
    labels = labels, xpd = TRUE) 
box() 
dev.off()