我将三张图表发送到同一页面上的pdf文件。尽管我的代码中具有相同的y坐标,但x轴标签处于不同的高度。我该如何解决?
以下是一个例子:
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()
答案 0 :(得分: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()